<?php namespace Phpcmf\Model\Quan;

// 自动执行方法
class Op extends \Phpcmf\Model
{

    public function is_favorite($tablename, $dirname) {

        if (!dr_in_array('favorites', \Phpcmf\Service::M('table')->get_cache_field($tablename)) ) {
            return dr_return_data(0, dr_lang('应用[模块内容收藏123]未安装到本模块[%s]', $dirname));
        }

        $id = (int)\Phpcmf\Service::L('input')->get('id');

        if (!$this->uid) {
            return dr_return_data(0, dr_lang('还没有登录'));
        } elseif (!$id) {
            return dr_return_data(0, dr_lang('id参数不完整'));
        }

        $favorite = $this->db->table($tablename.'_favorite')->where('cid', $id)->where('uid', $this->uid)->countAllResults();
        if ($favorite) {
            return dr_return_data(1, dr_lang('已经收藏'));
        } else {
            return dr_return_data(0, dr_lang('没有收藏'));
        }
    }
    
    public function run($tablename, $dirname) {

        /*if (!dr_in_array('favorites', \Phpcmf\Service::M('table')->get_cache_field($tablename)) ) {
            return dr_return_data(0, dr_lang('应用[模块内容收藏123]未安装到本模块[%s]', $dirname));
        }*/
        $shoucangzhi = (int)\Phpcmf\Service::L('input')->get('shoucang');
		

        $id = (int)\Phpcmf\Service::L('input')->get('id');
        if (!$this->uid) {
            return dr_return_data(0, dr_lang('还没有登录'));
        } elseif (!$id) {
            return dr_return_data(0, dr_lang('id参数不完整'));
        }
		
		// 创业金
		if(dr_is_app('chuangyejin')){
			$datamingcheng = \Phpcmf\Service::M()->table('1_quan_form_chuangyejin_shezhi')->where('dirname', 'chuangyejin')->getRow();
			$datamingchengs = dr_string2array($datamingcheng['setting']);
			$uidshuliang = \Phpcmf\Service::M()->db->table('1_quan_form_chuangyejin')->where('zhuangtai', 5)->where('uid', $this->uid)->where('DATEDIFF(from_unixtime(inputtime),now())=0')->countAllResults();
			$kaiguan = $datamingchengs['pages']['chuangyejin_shoucangkaiguan'];
			$mingcheng=$datamingchengs['pages']['chuangyejin_name'];
			$cishu = $datamingchengs['pages']['chuangyejin_shoucangcishu'];
			$jianqukaiguan = $datamingchengs['pages']['chuangyejin_qushoucangkaiguan'];
			
			if($kaiguan==1){
				if($uidshuliang <= $cishu){
					$zhi = '-'.$mingcheng.'奖励+'.$datamingchengs['pages']['chuangyejin_shoucangzhi'];
					$cishu = $cishu-$uidshuliang;
					
				} 
				
			} else {
				$zhi = '';
				$kaiguan = '';
				$cishu = '';
				
			}
			if($jianqukaiguan==1){
				$zhijian = '-'.$mingcheng.'减去-'.$datamingchengs['pages']['chuangyejin_qushoucangzhi'];
			} else {
				$zhijian='';
			}
		} else {
			$zhi = '';
			$kaiguan = '';
			$cishu = '';
			$zhijian='';
		}

        /*$data = $this->db->table($tablename.'_index')->where('id', $id)->countAllResults();
        if (!$data) {
            return dr_return_data(0, dr_lang('模块内容不存在'.$tablename));
        }*/

        $table = $tablename.'_form_son_favorite';
        if (!$this->db->tableExists($table) ) {
            return dr_return_data(0, dr_lang('应用[模块内容收藏]未安装到本模块[%s]', $dirname));
        }
		$shoucangshezhis = \Phpcmf\Service::M()->table('1_quan_shezhi')->where('dirname', 'tiezi')->getRow();
		$shoucangshezhi = dr_string2array($shoucangshezhis['setting']);
		//收藏奖励开关
		
        if ($shoucangzhi == 1) {
	        $shoucang = $this->db->table($table)->where('cid', $id)->where('uid', $this->uid)->get()->getRowArray();
	        if($shoucang){
	            $msg = dr_string2array(['shoucangzhi' => 1,
			    'value' => '已经收藏',
				'jifen' => '',]);
	        } else {
	            $msg = dr_string2array(['shoucangzhi' => 0,
			    'value' => '没有收藏',
				'jifen' => '',]);
	        }
	        
	        return dr_return_data(1, $msg);
	    }

        $favorite = $this->db->table($table)->where('cid', $id)->where('uid', $this->uid)->get()->getRowArray();
        if ($favorite) {
            // 已经收藏了,我们就删除它
            //$msg = dr_lang('取消收藏');
			//收藏开关全站统一
			if (intval($shoucangshezhi['pages']['setting']['tiezi_shoucang_kaiguan']) == 0) {
				if(intval($shoucangshezhi['pages']['setting']['shoucangscorefu']) == 0){
					//扣取值等于0 表示关闭
					$msg = dr_string2array(['status' => 1,
					    'value' => '取消收藏'.$zhijian,
						'jifen' => '',]);
					// 挂钩 取消收藏之后
					$hooksdata = [
						'id'=> $id,
						'uid' => $this->uid,
						'data'=> $favorite,
					];
					\Phpcmf\Hooks::trigger('qushoucang_hou', $hooksdata);
				} else {
					//扣取值大于0
					$shoucangfuzhi = intval($shoucangshezhi['pages']['setting']['shoucangscorefu']);
					$msg = dr_string2array(['status' => 1,
					    'value' => '取消收藏'.$zhijian,
						'jifen' => '-'.$shoucangfuzhi.' 积分',]);
					\Phpcmf\Service::M('member')->add_score($this->uid, -$shoucangfuzhi, $note = '取消扣取收藏', $url = '', $mark = '', $count = 0);
				    // 挂钩 取消收藏之后
					$hooksdata = [
						'id'=> $id,
						'uid' => $this->uid,
						'data'=> $favorite,
					];
					\Phpcmf\Hooks::trigger('qushoucang_hou', $hooksdata);
				}
				
			
			} else {
				//按照用户组设置（还在开发中...）
				$msg = dr_string2array(['status' => 1,
				    'value' => '取消收藏',
					'jifen' => '',]);
			}
			
            $this->db->table($table)->where('id', intval($favorite['id']))->delete();
        } else {
            if (!\Phpcmf\Service::M()->db->fieldExists('inputtime', $table)) {
                \Phpcmf\Service::M()->query('ALTER TABLE `'.$table.'` ADD `inputtime` int(10) unsigned DEFAULT \'0\' COMMENT \'操作时间\';');
            }
			//收藏开关全站统一
			if (intval($shoucangshezhi['pages']['setting']['tiezi_shoucang_kaiguan']) == 0) {
				if(intval($shoucangshezhi['pages']['setting']['shoucangscorejia']) == 0){
					$msg = dr_string2array(['status' => 1,
					    'value' => '收藏成功'.$zhi,
						'jifen' => '',]);
					// 挂钩 收藏成功之后
					$hooksdata = [
						'id'=> $id,
						'uid' => $this->uid,
						'data'=> $favorite,
					];
					\Phpcmf\Hooks::trigger('shoucang_hou', $hooksdata);
				} else {
					//奖励值大于0
					$shoucangjiazhi = intval($shoucangshezhi['pages']['setting']['shoucangscorejia']);
					$msg = dr_string2array(['status' => 1,
					    'value' => '收藏成功'.$zhi,
						'jifen' => '+'.$shoucangjiazhi.' 积分',]);
					\Phpcmf\Service::M('member')->add_score($this->uid, $shoucangjiazhi, $note = '收藏奖励', $url = '', $mark = '', $count = 0);
					// 挂钩 收藏成功之后
					$hooksdata = [
						'id'=> $id,
						'uid' => $this->uid,
						'data'=> $favorite,
					];
					\Phpcmf\Hooks::trigger('shoucang_hou', $hooksdata);
				}
				
				
			} else {
				//根据用户组设置（开发中...）
				$msg = dr_string2array(['status' => 1,
				    'value' => '收藏成功',
					'jifen' => '',]);
				
			}
            //$msg = dr_lang('收藏成功');
			
            $this->db->table($table)->insert(array(
                'cid' => $id,
                'uid' => $this->uid,
                'inputtime' => SYS_TIME
            ));
        }

        // 更新数量
        $c = $this->db->table($tablename.'_form_son_favorite')->where('cid', $id)->countAllResults();
        $this->db->table($tablename.'_form_son')->where('id', $id)->set('favorites', $c)->update();
        \Phpcmf\Service::M('cache')->update_data_cache();

        // 返回结果
        return dr_return_data(1, $msg, $c, $c);

    }
	//置顶
	public function zhiding($tablename, $dirname, $admin) {
	
	
	    $id = (int)\Phpcmf\Service::L('input')->get('id');
	    if (!$this->uid) {
	        return dr_return_data(0, dr_lang('还没有登录'));
	    } elseif (!$id) {
	        return dr_return_data(0, dr_lang('id参数不完整'));
	    }
	
	    $table = $tablename.'_form_son';
	    /*if (!$this->db->tableExists($table) ) {
	        return dr_return_data(0, dr_lang('应用[模块内容收藏]未安装到本模块[%s]', $dirname));
	    }*/
		
	    if ($admin == 1) {
			$zhidings = $this->db->table($table)->where('id', $id)->where('zhiding', 1)->get()->getRowArray();
		} else {
			$zhidings = $this->db->table($table)->where('id', $id)->where('uid', $this->uid)->where('zhiding', 1)->get()->getRowArray();
			//判断作者
			$zuozhes = $this->db->table($table)->where('id', $id)->where('uid', $this->uid)->get()->getRowArray();
			if(!$zuozhes){
				$msg = dr_string2array(['status' => 0,
				    'value' => '不是您的帖子，无法设置',
					'jifen' => '',]);
			}
		}
	    
	    if ($zhidings) {
	        // 已经置顶
	        //$msg = dr_lang('取消置顶');
			$msg = dr_string2array(['status' => 1,
			    'value' => '取消置顶成功',
				'jifen' => '',]);
			$this->db->table($table)->where('id', $id)->set('zhiding', 0)->update();
	
	    } else {
	       
	        //$msg = dr_lang('收藏成功');
			$msg = dr_string2array(['status' => 1,
			    'value' => '设置置顶成功',
				'jifen' => '',]);
			
	        $this->db->table($table)->where('id', $id)->set('zhiding', 1)->update();
	    }
	
	    // 返回结果
	    return dr_return_data(1, $msg, $c, $c);
	
	}
	//精华
	public function jinghua($tablename, $dirname, $admin) {
	
	
	    $id = (int)\Phpcmf\Service::L('input')->get('id');
	    if (!$this->uid) {
	        return dr_return_data(0, dr_lang('还没有登录'));
	    } elseif (!$id) {
	        return dr_return_data(0, dr_lang('id参数不完整'));
	    }
	
	    $table = $tablename.'_form_son';
	    /*if (!$this->db->tableExists($table) ) {
	        return dr_return_data(0, dr_lang('应用[模块内容收藏]未安装到本模块[%s]', $dirname));
	    }*/
		
	    if ($admin == 1) {
			$jinghuas = $this->db->table($table)->where('id', $id)->where('jinghua', 1)->get()->getRowArray();
		} else {
			$jinghuas = $this->db->table($table)->where('id', $id)->where('uid', $this->uid)->where('jinghua', 1)->get()->getRowArray();
			//判断作者
			$zuozhes = $this->db->table($table)->where('id', $id)->where('uid', $this->uid)->get()->getRowArray();
			if(!$zuozhes){
				$msg = dr_string2array(['status' => 0,
				    'value' => '不是您的帖子，无法设置',
					'jifen' => '',]);
			}
		}
	    
	    if ($jinghuas) {
	        // 已经精华
	        //$msg = dr_lang('取消精华');
			$msg = dr_string2array(['status' => 1,
			    'value' => '取消精华成功',
				'jifen' => '',]);
			$this->db->table($table)->where('id', $id)->set('jinghua', 0)->update();
	
	    } else {
	       
	        //$msg = dr_lang('收藏成功');
			$msg = dr_string2array(['status' => 1,
			    'value' => '设置精华成功',
				'jifen' => '',]);
			
	        $this->db->table($table)->where('id', $id)->set('jinghua', 1)->update();
	    }
	
	    // 返回结果
	    return dr_return_data(1, $msg, $c, $c);
	
	}
	//全站置顶
	public function qzzd($tablename, $dirname, $admin) {
	
	
	    $id = (int)\Phpcmf\Service::L('input')->get('id');
	    if (!$this->uid) {
	        return dr_return_data(0, dr_lang('还没有登录'));
	    } elseif (!$id) {
	        return dr_return_data(0, dr_lang('id参数不完整'));
	    }
	
	    $table = $tablename.'_form_son';
	    /*if (!$this->db->tableExists($table) ) {
	        return dr_return_data(0, dr_lang('应用[模块内容收藏]未安装到本模块[%s]', $dirname));
	    }*/
		
	    if ($admin == 1) {
			$qzzds = $this->db->table($table)->where('id', $id)->where('qzzd', 1)->get()->getRowArray();
		} else {
			$qzzds = $this->db->table($table)->where('id', $id)->where('uid', $this->uid)->where('qzzd', 1)->get()->getRowArray();
			//判断作者
			$zuozhes = $this->db->table($table)->where('id', $id)->where('uid', $this->uid)->get()->getRowArray();
			if(!$zuozhes){
				$msg = dr_string2array(['status' => 0,
				    'value' => '不是您的帖子，无法设置',
					'jifen' => '',]);
			}
		}
	    
	    if ($qzzds) {
	        // 已经精华
	        //$msg = dr_lang('取消精华');
			$msg = dr_string2array(['status' => 1,
			    'value' => '取消全置成功',
				'jifen' => '',]);
			$this->db->table($table)->where('id', $id)->set('qzzd', 0)->update();
	
	    } else {
	       
	        //$msg = dr_lang('收藏成功');
			$msg = dr_string2array(['status' => 1,
			    'value' => '设置全置成功',
				'jifen' => '',]);
			
	        $this->db->table($table)->where('id', $id)->set('qzzd', 1)->update();
	    }
	
	    // 返回结果
	    return dr_return_data(1, $msg, $c, $c);
	
	}
	//首页置顶
	public function shouyezhiding($tablename, $dirname, $admin) {
	
	
	    $id = (int)\Phpcmf\Service::L('input')->get('id');
	    if (!$this->uid) {
	        return dr_return_data(0, dr_lang('还没有登录'));
	    } elseif (!$id) {
	        return dr_return_data(0, dr_lang('id参数不完整'));
	    }
	
	    $table = $tablename.'_form_son';
	    /*if (!$this->db->tableExists($table) ) {
	        return dr_return_data(0, dr_lang('应用[模块内容收藏]未安装到本模块[%s]', $dirname));
	    }*/
	    if ($admin == 1) {
			$shouyezhidings = $this->db->table($table)->where('id', $id)->where('tuijian', 1)->get()->getRowArray();
		} else {
			$shouyezhidings = $this->db->table($table)->where('id', $id)->where('uid', $this->uid)->where('tuijian', 1)->get()->getRowArray();
			//判断作者
			$zuozhes = $this->db->table($table)->where('id', $id)->where('uid', $this->uid)->get()->getRowArray();
			if(!$zuozhes){
				$msg = dr_string2array(['status' => 0,
				    'value' => '不是您的帖子，无法设置',
					'jifen' => '',]);
			}
		}
	    
	    if ($shouyezhidings) {
	        // 已经置顶
	        //$msg = dr_lang('取消置顶');
			$msg = dr_string2array(['status' => 1,
			    'value' => '取消置顶成功',
				'jifen' => '',]);
			$this->db->table($table)->where('id', $id)->set('tuijian', 0)->update();
	
	    } else {
	       
	        //$msg = dr_lang('收藏成功');
			$msg = dr_string2array(['status' => 1,
			    'value' => '设置置顶成功',
				'jifen' => '',]);
			
	        $this->db->table($table)->where('id', $id)->set('tuijian', 1)->update();
	    }
	
	    // 返回结果
	    return dr_return_data(1, $msg, $c, $c);
	
	}
	//审核帖子
	public function shenhe($tablename, $dirname, $admin) {
	
	
	    $id = (int)\Phpcmf\Service::L('input')->get('id');
	    if (!$this->uid) {
	        return dr_return_data(0, dr_lang('还没有登录'));
	    } elseif (!$id) {
	        return dr_return_data(0, dr_lang('id参数不完整'));
	    }
	
	    $table = $tablename.'_form_son';
	    /*if (!$this->db->tableExists($table) ) {
	        return dr_return_data(0, dr_lang('应用[模块内容收藏]未安装到本模块[%s]', $dirname));
	    }*/
	    //判断圈主
	    $quanids = $this->db->table($table)->where('cid', $id)->get()->getRowArray();
	    $quanzhushenhes = $this->db->table($tablename)->where('id', $quanids['id'])->where('uid', $this->uid)->get()->getRowArray();
	    if ($admin == 1 || $quanzhushenhes) {
			$shenhes = $this->db->table($table)->where('id', $id)->where('shenhe', 1)->get()->getRowArray();
		} else {
			$shenhes = $this->db->table($table)->where('id', $id)->where('uid', $this->uid)->where('shenhe', 1)->get()->getRowArray();
			//判断作者
			$zuozhes = $this->db->table($table)->where('id', $id)->where('uid', $this->uid)->get()->getRowArray();
			if(!$zuozhes){
				$msg = dr_string2array(['status' => 0,
				    'value' => '不是您的帖子，无法设置',
					'jifen' => '',]);
			}
		}
	    
	    if ($shenhes) {
	        // 已经审核
	        //$msg = dr_lang('取消审核');
			$msg = dr_string2array(['status' => 1,
			    'value' => '取消审核',
				'jifen' => '',]);
			$this->db->table($table)->where('id', $id)->set('shenhe', 0)->update();
	
	    } else {
	       
	        //$msg = dr_lang('审核');
			$msg = dr_string2array(['status' => 1,
			    'value' => '设置审核成功',
				'jifen' => '',]);
			
	        $this->db->table($table)->where('id', $id)->set('shenhe', 1)->update();
	    }
	
	    // 返回结果
	    return dr_return_data(1, $msg, $c, $c);
	
	}
	/*短信已读*/
	public function yidu($tablename, $dirname) {
		$id = (int)\Phpcmf\Service::L('input')->get('id');
		if (!$this->uid) {
			$msg = dr_string2array(['status' => 0,
			    'value' => '还没有登录',
				'jifen' => '',]);
		    return dr_return_data(0, $msg);
		} elseif (!$id) {
			$msg = dr_string2array(['status' => 0,
			    'value' => 'id参数不完整',
				'jifen' => '',]);
		    return dr_return_data(0, $msg);
		}
		$table = '1_duixin';
		//$yidu = $this->db->table($table)->where('id', $id)->where('uid', $this->uid)->get()->getRowArray();
		$this->db->table($table)->where('id', $id)->where('shouxinren', $this->uid)->update(['yidu' => 1]);
		// 返回结果
		return dr_return_data(1, $msg, 0);
	}
	/*点赞*/
	public function zan($tablename, $dirname) {
	
	    /*if (!dr_in_array('favorites', \Phpcmf\Service::M('table')->get_cache_field($tablename)) ) {
	        return dr_return_data(0, dr_lang('应用[模块内容收藏123]未安装到本模块[%s]', $dirname));
	    }*/
	    $zanzhi = (int)\Phpcmf\Service::L('input')->get('zan');
	    $id = (int)\Phpcmf\Service::L('input')->get('id');

	    if (!$this->uid) {
			$msg = dr_string2array(['status' => 0,
			    'value' => '还没有登录',
				'jifen' => '',]);
	        return dr_return_data(0, $msg);
	    } elseif (!$id) {
			$msg = dr_string2array(['status' => 0,
			    'value' => 'id参数不完整',
				'jifen' => '',]);
	        return dr_return_data(0, $msg);
	    }
	    // 创业金
	    if(dr_is_app('chuangyejin')){
	    	$datamingcheng = \Phpcmf\Service::M()->table('1_quan_form_chuangyejin_shezhi')->where('dirname', 'chuangyejin')->getRow();
	    	$datamingchengs = dr_string2array($datamingcheng['setting']);
	    	$uidshuliang = \Phpcmf\Service::M()->db->table('1_quan_form_chuangyejin')->where('zhuangtai', 4)->where('uid', $this->uid)->where('DATEDIFF(from_unixtime(inputtime),now())=0')->countAllResults();
	    	$kaiguan = $datamingchengs['pages']['chuangyejin_dianzankaiguan'];
	    	$mingcheng=$datamingchengs['pages']['chuangyejin_name'];
			$cishu = $datamingchengs['pages']['chuangyejin_zancishu'];
			$jianqukaiguan = $datamingchengs['pages']['chuangyejin_qudianzankaiguan'];
			
	    	if($kaiguan==1){
	    		if($uidshuliang <= $cishu){
	    			$zhi = '-'.$mingcheng.'奖励+'.$datamingchengs['pages']['chuangyejin_zanzhi'];
	    			$cishu = $cishu-$uidshuliang;
					
	    		} 
				
	    	} else {
	    		$zhi = '';
	    		$kaiguan = '';
	    		$cishu = '';
				
	    	}
			if($jianqukaiguan==1){
				$zhijian = '-'.$mingcheng.'减去-'.$datamingchengs['pages']['chuangyejin_quzanzhi'];
			} else {
				$zhijian='';
			}
	    } else {
	    	$zhi = '';
	    	$kaiguan = '';
	    	$cishu = '';
			$zhijian='';
	    }
	    /*$data = $this->db->table($tablename.'_index')->where('id', $id)->countAllResults();
	    if (!$data) {
	        return dr_return_data(0, dr_lang('模块内容不存在'.$tablename));
	    }*/
	
	    $table = $tablename.'_form_son_zan';
	    if (!$this->db->tableExists($table) ) {
	        return dr_return_data(0, dr_lang('应用[模块内容点赞]未安装到本模块[%s]', $dirname));
	    }
		
	    $dianzanshezhis = \Phpcmf\Service::M()->table('1_quan_shezhi')->where('dirname', 'tiezi')->getRow();
	    $dianzanshezhi = dr_string2array($dianzanshezhis['setting']);
	    if ($zanzhi == 1) {
	        $zan = $this->db->table($table)->where('cid', $id)->where('uid', $this->uid)->get()->getRowArray();
	        if($zan){
	            $msg = dr_string2array(['zanzhi' => 1,
			    'value' => '已经点赞',
				'jifen' => '',]);
	        } else {
				
	            $msg = dr_string2array(['zanzhi' => 0,
			    'value' => '没有点赞',
				'jifen' => '',]);
	        }
	        
	        return dr_return_data(1, $msg);
	    }
	
	    $zan = $this->db->table($table)->where('cid', $id)->where('uid', $this->uid)->get()->getRowArray();
		$tabledata = $tablename.'_form_son';
		$zandata = $this->db->table($tabledata)->where('id', $id)->get()->getRowArray();
		//dr_debug('zan',$zandata);
		//标题
		if($zandata['title']){
			$zantitle = $zandata['title'];
		} else {
			$zantitle = dr_strcut(dr_clearhtml($zandata['neirong']), 20);
		}
	    if ($zan) {
	        // 已经点赞了,我们就删除它
			//取消点赞奖励积分
			$url='/index.php?s=quan&c=son&m=index&id='.$id;
			//点赞开关全站统一
			if (intval($dianzanshezhi['pages']['setting']['tiezi_dianzan_kaiguan']) == 0) {
				if(intval($dianzanshezhi['pages']['setting']['scorefu']) == 0){
					// 没有扣取
					$msg = dr_string2array(['status' => 0,
					    'value' => '取消点赞'.$zhijian,
						'jifen' => '',]);
					// 挂钩点 取消点赞完成之后
					$hooksdata = [
						'id'=> $id,
						'uid' => $this->uid,
						'data'=> $zandata,
					];
					\Phpcmf\Hooks::trigger('quzan_hou', $hooksdata);
				} else {
					//扣取
					$scorefuzhi = intval($dianzanshezhi['pages']['setting']['scorefu']);
					$msg = dr_string2array(['status' => 0,
					    'value' => '取消点赞'.$zhijian,
						'jifen' => '-'.$scorefuzhi.' 积分',]);
					\Phpcmf\Service::M('member')->add_score($this->uid, -$scorefuzhi, $note = '取消点赞扣取', $url, $mark = '', $count = 1);
					// 挂钩点 取消点赞完成之后
					
					$hooksdata = [
						'id'=> $id,
						'uid' => $this->uid,
						'data'=> $zandata,
					];
					\Phpcmf\Hooks::trigger('quzan_hou', $hooksdata);
				}
			} else {
				//根据用户组（开发中...）
				$msg = dr_string2array(['status' => 0,
				    'value' => '取消点赞',
					'jifen' => '',]);
			}
	        //$msg = dr_lang('取消点赞 -1 积分');
			/*$msg = $this->_json(1, '取消点赞', [
			    'status' => 0,
			    'value' => '取消点赞',
			]);*/
	        $this->db->table($table)->where('id', intval($zan['id']))->delete();
	    } else {
	        if (!\Phpcmf\Service::M()->db->fieldExists('inputtime', $table)) {
	            \Phpcmf\Service::M()->query('ALTER TABLE `'.$table.'` ADD `inputtime` int(10) unsigned DEFAULT \'0\' COMMENT \'操作时间\';');
	        }
			//点赞奖励积分
			$url='/index.php?s=quan&c=son&m=index&id='.$id;
			
	        //$msg = dr_lang('点赞成功 +1 积分');
			/*$msg = $this->_json(1, '点赞成功', [
			    'status' => 0,
			    'value' => '点赞成功',
			]);*/
			//点赞开关全站统一
			if (intval($dianzanshezhi['pages']['setting']['tiezi_dianzan_kaiguan']) == 0) {
				if(intval($dianzanshezhi['pages']['setting']['scorejia']) == 0){
					$msg = dr_string2array(['status' => 1,
					    'value' => '点赞成功'.$zhi,
						'jifen' => '',]);
					// 挂钩点 点赞完成之后
					$hooksdata = [
						'id'=> $id,
						'uid' => $this->uid,
						'data'=> $zandata,
					];
					\Phpcmf\Hooks::trigger('zan_hou', $hooksdata);
				} else {
					//点赞奖励
					$scorejiazhi = intval($dianzanshezhi['pages']['setting']['scorejia']);
					$msg = dr_string2array(['status' => 1,
					    'value' => '点赞成功'.$zhi,
						'jifen' => '+'.$scorejiazhi.' 积分',]);
					\Phpcmf\Service::M('member')->add_score($this->uid, $scorejiazhi, $note = '点赞奖励', $url, $mark = '', $count = 1);
					// 挂钩点 点赞完成之后
					$hooksdata = [
						'id'=> $id,
						'uid' => $this->uid,
						'data'=> $zandata,
					];
					\Phpcmf\Hooks::trigger('zan_hou', $hooksdata);
				}
			} else {
				//用户组设置
				$msg = dr_string2array(['status' => 1,
				    'value' => '点赞成功',
					'jifen' => '',]);
			}
			if($this->uid != $zandata['uid']){
				//通知
				$data = [
					'catid'=> 4, //类型
					'title' => '点赞', //标题
					'zhiding' => '', //置顶
					'content'=> $zantitle, //通知内容
					'uid'=> $this->uid, //发布人的uid
					'faxinren'=> $this->uid, //发布人的uid
					'shouxinren'=> (int)$zandata['uid'],//收信人
					'tupian'=> '', //图片
					'shipin'=> '', //视频
					'yuyin'=> '', //语音
					'fujian'=> '', //附件
					'yidu'=> 0, //已读
					'quanziid'=> $zandata['cid'], //圈子ID
					'quantieid'=> $zandata['id'], //圈帖ID
					'url' => '',
				];
				\Phpcmf\Service::M('auth')->addtongzhi($data);
				//微信通知
				//微信通知
				$data = \Phpcmf\Service::M()->table('app_weixin_shezhi_tongzhi')->where('id', 1)->getRow();
				if (!$data) {
					$this->_admin_msg(0, dr_lang('模块#%s不存在', 'weixin'));
				}
				
				
				$data['setting'] = dr_string2array($data['setting']);
				if (!isset($data['setting']['pages'])) {
					$data['setting']['pages'] = [];
				}
				$muban = $data['setting']['pages'];
				$biaoqiana = $muban['zanbiaoqiana'];
				$biaoqianb = $muban['zanbiaoqianb'];
				$biaoqianc = $muban['zanbiaoqianc'];
				$user=dr_member_info($this->uid);
				$www = SITE_URL;
				\Phpcmf\Service::L('Notice')->send_notice_user("点赞", $zandata['uid'], [], [
					'weixin' => [
						'tpl_content' => [
							'id' => $muban['dianzan'],
							'param' => [
								$biaoqiana => [
								  'value' => dr_date(SYS_TIME),
								  'color' => '#173177',
								],
								$biaoqianb => [
								  'value' => $zantitle,
								  'color' => '#173177',
								],
								$biaoqianc => [
								  'value' => $user['username'].' : 给你点赞了',
								  'color' => '#173177',
								],
							],
							'url' => $www.'/index.php?s=quan&c=son&id='.$zandata['id'],
						],
					],
				]);
			}
			
	        $this->db->table($table)->insert(array(
	            'cid' => $id,
	            'uid' => $this->uid,
	            'inputtime' => SYS_TIME
	        ));
	    }
	
	    // 更新数量
	    $c = $this->db->table($tablename.'_form_son_zan')->where('cid', $id)->countAllResults();
	    $this->db->table($tablename.'_form_son')->where('id', $id)->set('zan', $c)->update();
	    \Phpcmf\Service::M('cache')->update_data_cache();
	
	    // 返回结果
	    return dr_return_data(1, $msg, $c);
	
	}
	/*进度*/
	public function jindu($tablename, $dirname) {
	
	    $id = (int)\Phpcmf\Service::L('input')->get('id');
		$quanid = (int)\Phpcmf\Service::L('input')->get('quanid');
		$this->index = $this->db->table($tablename)->where('id', $quanid)->get()->getRowArray();
		//dr_debug('$indexuid', $this->index);
	    if (!$this->uid) {
			$msg = dr_string2array(['status' => 0,
			    'value' => '还没有登录',
				'jifen' => '',]);
	        return dr_return_data(0, $msg);
	    } elseif (!$id) {
			$msg = dr_string2array(['status' => 0,
			    'value' => 'id参数不完整',
				'jifen' => '',]);
	        return dr_return_data(0, $msg);
	    }
	
	    $table = $tablename.'_jindu';
	    if (!$this->db->tableExists($table) ) {
	        return dr_return_data(0, dr_lang('没有进度数据库表[%s]', $dirname));
	    }
		
		
		if ($this->index['uid'] != $this->uid) {
			
			$msg = dr_string2array(['status' => 0,
			    'value' => '您不是圈主，无权操作',
				'jifen' => '',]);
			return dr_return_data(0, $msg, $c);
		}
	
	    $jindu = $this->db->table($table)->where('cid', $id)->where('leixing', 1)->where('uid', $this->uid)->get()->getRowArray();
	    if ($jindu) {
	        // 取消进度,我们就删除它
			
			$msg = dr_string2array(['status' => 0,
			    'value' => '取消需求',
				'jifen' => '',]);
	        $this->db->table($table)->where('cid', $id)->delete();
			//更新
			$this->db->table($tablename.'_form_son')->where('id', $id)->update(['jindu' => 0]);
	    } else {
			//进度
			$msg = dr_string2array(['status' => 1,
			    'value' => '开启需求',
				'jifen' => '',]);
	        $this->db->table($table)->insert(array(
	            'cid' => $id,
	            'uid' => $this->uid,
				'leixing' => 1,
	            'inputtime' => SYS_TIME
	        ));
			//更新
			$this->db->table($tablename.'_form_son')->where('id', $id)->update(['jindu' => 1]);
	    }
	
	    // 更新缓存
	    //$c = $this->db->table($tablename.'_form_son_zan')->where('cid', $id)->countAllResults();
	    //$this->db->table($tablename.'_form_son')->where('id', $id)->set('zan', $c)->update();
	    \Phpcmf\Service::M('cache')->update_data_cache();
	
	    // 返回结果
	    return dr_return_data(1, $msg, $c);
	
	}
	/*进度-排期*/
	public function jindupaiqi($tablename, $dirname) {
	
	    $id = (int)\Phpcmf\Service::L('input')->get('id');
		$quanid = (int)\Phpcmf\Service::L('input')->get('quanid');
		$this->index = $this->db->table($tablename)->where('id', $quanid)->get()->getRowArray();
		//dr_debug('$indexuid', $this->index);
	    if (!$this->uid) {
			$msg = dr_string2array(['status' => 0,
			    'value' => '还没有登录',
				'jifen' => '',]);
	        return dr_return_data(0, $msg);
	    } elseif (!$id) {
			$msg = dr_string2array(['status' => 0,
			    'value' => 'id参数不完整',
				'jifen' => '',]);
	        return dr_return_data(0, $msg);
	    }
	
	    $table = $tablename.'_jindu';
	    if (!$this->db->tableExists($table) ) {
	        return dr_return_data(0, dr_lang('没有进度数据库表[%s]', $dirname));
	    }
		
		
		if ($this->index['uid'] != $this->uid) {
			
			$msg = dr_string2array(['status' => 0,
			    'value' => '您不是圈主，无权操作',
				'jifen' => '',]);
			return dr_return_data(0, $msg, $c);
		}
	
	    $jindu = $this->db->table($table)->where('cid', $id)->where('leixing', 2)->where('uid', $this->uid)->get()->getRowArray();
	    if ($jindu) {
	        // 取消进度,我们就删除它
			
			$msg = dr_string2array(['status' => 0,
			    'value' => '取消排期',
				'jifen' => '',]);
	        $this->db->table($table)->where('cid', $id)->where('leixing', 2)->delete();
	
	    } else {
			//进度
			$msg = dr_string2array(['status' => 1,
			    'value' => '开启排期',
				'jifen' => '',]);
	        $this->db->table($table)->insert(array(
	            'cid' => $id,
	            'uid' => $this->uid,
				'leixing' => 2,
	            'inputtime' => SYS_TIME
	        ));
	
	    }
	
	    // 更新缓存
	    //$c = $this->db->table($tablename.'_form_son_zan')->where('cid', $id)->countAllResults();
	    //$this->db->table($tablename.'_form_son')->where('id', $id)->set('zan', $c)->update();
	    \Phpcmf\Service::M('cache')->update_data_cache();
	
	    // 返回结果
	    return dr_return_data(1, $msg, $c);
	
	}
	/*进度-开发*/
	public function jindukaifa($tablename, $dirname) {
	
	    $id = (int)\Phpcmf\Service::L('input')->get('id');
		$quanid = (int)\Phpcmf\Service::L('input')->get('quanid');
		$this->index = $this->db->table($tablename)->where('id', $quanid)->get()->getRowArray();
		//dr_debug('$indexuid', $this->index);
	    if (!$this->uid) {
			$msg = dr_string2array(['status' => 0,
			    'value' => '还没有登录',
				'jifen' => '',]);
	        return dr_return_data(0, $msg);
	    } elseif (!$id) {
			$msg = dr_string2array(['status' => 0,
			    'value' => 'id参数不完整',
				'jifen' => '',]);
	        return dr_return_data(0, $msg);
	    }
	
	    $table = $tablename.'_jindu';
	    if (!$this->db->tableExists($table) ) {
	        return dr_return_data(0, dr_lang('没有进度数据库表[%s]', $dirname));
	    }
		
		
		if ($this->index['uid'] != $this->uid) {
			
			$msg = dr_string2array(['status' => 0,
			    'value' => '您不是圈主，无权操作',
				'jifen' => '',]);
			return dr_return_data(0, $msg, $c);
		}
	
	    $jindu = $this->db->table($table)->where('cid', $id)->where('leixing', 3)->where('uid', $this->uid)->get()->getRowArray();
	    if ($jindu) {
	        // 取消进度,我们就删除它
			
			$msg = dr_string2array(['status' => 0,
			    'value' => '取消开发',
				'jifen' => '',]);
	        $this->db->table($table)->where('cid', $id)->where('leixing', 3)->delete();
	
	    } else {
			//进度
			$msg = dr_string2array(['status' => 1,
			    'value' => '开启开发',
				'jifen' => '',]);
	        $this->db->table($table)->insert(array(
	            'cid' => $id,
	            'uid' => $this->uid,
				'leixing' => 3,
	            'inputtime' => SYS_TIME
	        ));
	
	    }
	
	    // 更新缓存
	    //$c = $this->db->table($tablename.'_form_son_zan')->where('cid', $id)->countAllResults();
	    //$this->db->table($tablename.'_form_son')->where('id', $id)->set('zan', $c)->update();
	    \Phpcmf\Service::M('cache')->update_data_cache();
	
	    // 返回结果
	    return dr_return_data(1, $msg, $c);
	
	}
	/*进度-完成*/
	public function jinduwancheng($tablename, $dirname) {
	
	    $id = (int)\Phpcmf\Service::L('input')->get('id');
		$quanid = (int)\Phpcmf\Service::L('input')->get('quanid');
		$this->index = $this->db->table($tablename)->where('id', $quanid)->get()->getRowArray();
		//dr_debug('$indexuid', $this->index);
	    if (!$this->uid) {
			$msg = dr_string2array(['status' => 0,
			    'value' => '还没有登录',
				'jifen' => '',]);
	        return dr_return_data(0, $msg);
	    } elseif (!$id) {
			$msg = dr_string2array(['status' => 0,
			    'value' => 'id参数不完整',
				'jifen' => '',]);
	        return dr_return_data(0, $msg);
	    }
	
	    $table = $tablename.'_jindu';
	    if (!$this->db->tableExists($table) ) {
	        return dr_return_data(0, dr_lang('没有进度数据库表[%s]', $dirname));
	    }
		
		
		if ($this->index['uid'] != $this->uid) {
			
			$msg = dr_string2array(['status' => 0,
			    'value' => '您不是圈主，无权操作',
				'jifen' => '',]);
			return dr_return_data(0, $msg, $c);
		}
	
	    $jindu = $this->db->table($table)->where('cid', $id)->where('leixing', 4)->where('uid', $this->uid)->get()->getRowArray();
	    if ($jindu) {
	        // 取消进度,我们就删除它
			
			$msg = dr_string2array(['status' => 0,
			    'value' => '取消完成',
				'jifen' => '',]);
	        $this->db->table($table)->where('cid', $id)->where('leixing', 4)->delete();
	
	    } else {
			//进度
			$msg = dr_string2array(['status' => 1,
			    'value' => '完成开发',
				'jifen' => '',]);
	        $this->db->table($table)->insert(array(
	            'cid' => $id,
	            'uid' => $this->uid,
				'leixing' => 4,
	            'inputtime' => SYS_TIME
	        ));
	
	    }
	
	    // 更新缓存
	    //$c = $this->db->table($tablename.'_form_son_zan')->where('cid', $id)->countAllResults();
	    //$this->db->table($tablename.'_form_son')->where('id', $id)->set('zan', $c)->update();
	    \Phpcmf\Service::M('cache')->update_data_cache();
	
	    // 返回结果
	    return dr_return_data(1, $msg, $c);
	
	}
	/*新增进度-完成*/
	public function jindudata($tablename, $dirname, $admin) {
	
	    $id = (int)\Phpcmf\Service::L('input')->get('id');
		$quanid = (int)\Phpcmf\Service::L('input')->get('quanid');
		$leixing = (int)\Phpcmf\Service::L('input')->get('leixing');
		$this->index = $this->db->table($tablename)->where('id', $quanid)->get()->getRowArray();
		//dr_debug('$indexuid', $this->index);
	    if (!$this->uid) {
			$msg = dr_string2array(['status' => 0,
			    'value' => '还没有登录',
				'jifen' => '',]);
	        return dr_return_data(0, $msg);
	    } elseif (!$id) {
			$msg = dr_string2array(['status' => 0,
			    'value' => 'id参数不完整',
				'jifen' => '',]);
	        return dr_return_data(0, $msg);
	    }
	
	    $table = $tablename.'_jindu';
	    if (!$this->db->tableExists($table) ) {
	        return dr_return_data(0, dr_lang('没有进度数据库表[%s]', $dirname));
	    }
		
		if($admin == 1){
			//管理员 待开发
		} elseif ($this->index['uid'] != $this->uid) {
			
			$msg = dr_string2array(['status' => 0,
			    'value' => '您不是圈主，无权操作',
				'jifen' => '',]);
			return dr_return_data(0, $msg, $c);
		}
	
	    $jindu = $this->db->table($table)->where('cid', $id)->where('leixing', $leixing)->where('uid', $this->uid)->get()->getRowArray();
	    if($leixing==1){
			$value = '开启进度';
		} elseif ($leixing==2){
			$value = '开启排期';
		} elseif ($leixing==3) {
			$value = '开启开发';
		} elseif ($leixing==4) {
			$value = '完成开发';
		}
		if ($jindu) {
	        // 取消进度,我们就删除它
			
			$msg = dr_string2array(['status' => 0,
			    'value' => '取消成功',
				'jifen' => '',]);
	        $this->db->table($table)->where('cid', $id)->where('leixing', $leixing)->delete();
	
	    } else {
			//进度
			$msg = dr_string2array(['status' => 1,
			    'value' => $value,
				'jifen' => '',]);
	        $this->db->table($table)->insert(array(
	            'cid' => $id,
	            'uid' => $this->uid,
				'leixing' => $leixing,
	            'inputtime' => SYS_TIME
	        ));
	
	    }
	
	    // 更新缓存
	    
	    \Phpcmf\Service::M('cache')->update_data_cache();
	
	    // 返回结果
	    return dr_return_data(1, $msg, $c);
	
	}
	//bug
	/*BUG进度-排期*/
	public function bugdata($tablename, $dirname, $admin) {
	
	    $id = (int)\Phpcmf\Service::L('input')->get('id');
		$quanid = (int)\Phpcmf\Service::L('input')->get('quanid');
		$leixing = (int)\Phpcmf\Service::L('input')->get('leixing');
		$this->index = $this->db->table($tablename)->where('id', $quanid)->get()->getRowArray();
		//dr_debug('$indexuid', $this->index);
	    if (!$this->uid) {
			$msg = dr_string2array(['status' => 0,
			    'value' => '还没有登录',
				'jifen' => '',]);
	        return dr_return_data(0, $msg);
	    } elseif (!$id) {
			$msg = dr_string2array(['status' => 0,
			    'value' => 'id参数不完整',
				'jifen' => '',]);
	        return dr_return_data(0, $msg);
	    }
	
	    $table = $tablename.'_bug';
	    if (!$this->db->tableExists($table) ) {
	        return dr_return_data(0, dr_lang('没有进度数据库表[%s]', $dirname));
	    }
		
		
		if($admin == 1){
			//管理员 待开发
		} elseif ($this->index['uid'] != $this->uid) {
			
			$msg = dr_string2array(['status' => 0,
			    'value' => '您不是圈主，无权操作',
				'jifen' => '',]);
			return dr_return_data(0, $msg, $c);
		}
	
	    $bug = $this->db->table($table)->where('cid', $id)->where('leixing', $leixing)->where('uid', $this->uid)->get()->getRowArray();
	    if($leixing==1){
	    	$value = '开启进度';
	    } elseif ($leixing==2){
	    	$value = '开启排期';
	    } elseif ($leixing==3) {
	    	$value = '开启开发';
	    } elseif ($leixing==4) {
	    	$value = '已修复';
	    }
		if ($bug) {
	        // 取消进度,我们就删除它
			
			$msg = dr_string2array(['status' => 0,
			    'value' => '取消排期',
				'leixing' => $leixing,
				'jifen' => '',]);
	        $this->db->table($table)->where('cid', $id)->where('leixing', $leixing)->delete();
	
	    } else {
			//进度
			$msg = dr_string2array(['status' => 1,
			    'value' => $value,
				'leixing' => $leixing,
				'jifen' => '',]);
	        $this->db->table($table)->insert(array(
	            'cid' => $id,
	            'uid' => $this->uid,
				'leixing' => $leixing,
	            'inputtime' => SYS_TIME
	        ));
	
	    }
	
	    // 更新缓存
	    //$c = $this->db->table($tablename.'_form_son_zan')->where('cid', $id)->countAllResults();
	    //$this->db->table($tablename.'_form_son')->where('id', $id)->set('zan', $c)->update();
	    \Phpcmf\Service::M('cache')->update_data_cache();
	
	    // 返回结果
	    return dr_return_data(1, $msg, $c);
	
	}
	/*BUG进度*/
	public function bug($tablename, $dirname) {
	
	    $id = (int)\Phpcmf\Service::L('input')->get('id');
		$quanid = (int)\Phpcmf\Service::L('input')->get('quanid');
		$this->index = $this->db->table($tablename)->where('id', $quanid)->get()->getRowArray();
		//dr_debug('$indexuid', $this->index);
	    if (!$this->uid) {
			$msg = dr_string2array(['status' => 0,
			    'value' => '还没有登录',
				'jifen' => '',]);
	        return dr_return_data(0, $msg);
	    } elseif (!$id) {
			$msg = dr_string2array(['status' => 0,
			    'value' => 'id参数不完整',
				'jifen' => '',]);
	        return dr_return_data(0, $msg);
	    }
	
	    $table = $tablename.'_bug';
	    if (!$this->db->tableExists($table) ) {
	        return dr_return_data(0, dr_lang('没有进度数据库表[%s]', $dirname));
	    }
		
		
		if ($this->index['uid'] != $this->uid) {
			
			$msg = dr_string2array(['status' => 0,
			    'value' => '您不是圈主，无权操作',
				'jifen' => '',]);
			return dr_return_data(0, $msg, $c);
		}
	
	    $bug = $this->db->table($table)->where('cid', $id)->where('leixing', 1)->where('uid', $this->uid)->get()->getRowArray();
	    if ($bug) {
	        // 取消进度,我们就删除它
			
			$msg = dr_string2array(['status' => 0,
			    'value' => '取消需求',
				'jifen' => '',]);
	        $this->db->table($table)->where('cid', $id)->delete();
			//更新
			$this->db->table($tablename.'_form_son')->where('id', $id)->update(['bug' => 0]);
	    } else {
			//进度
			$msg = dr_string2array(['status' => 1,
			    'value' => '开启修复',
				'jifen' => '',]);
	        $this->db->table($table)->insert(array(
	            'cid' => $id,
	            'uid' => $this->uid,
				'leixing' => 1,
	            'inputtime' => SYS_TIME
	        ));
			//更新
			$this->db->table($tablename.'_form_son')->where('id', $id)->update(['bug' => 1]);
	    }
	
	    // 更新缓存
	    //$c = $this->db->table($tablename.'_form_son_zan')->where('cid', $id)->countAllResults();
	    //$this->db->table($tablename.'_form_son')->where('id', $id)->set('zan', $c)->update();
	    \Phpcmf\Service::M('cache')->update_data_cache();
	
	    // 返回结果
	    return dr_return_data(1, $msg, $c);
	
	}
	/*BUG进度-排期*/
	public function bugpaiqi($tablename, $dirname) {
	
	    $id = (int)\Phpcmf\Service::L('input')->get('id');
		$quanid = (int)\Phpcmf\Service::L('input')->get('quanid');
		$this->index = $this->db->table($tablename)->where('id', $quanid)->get()->getRowArray();
		//dr_debug('$indexuid', $this->index);
	    if (!$this->uid) {
			$msg = dr_string2array(['status' => 0,
			    'value' => '还没有登录',
				'jifen' => '',]);
	        return dr_return_data(0, $msg);
	    } elseif (!$id) {
			$msg = dr_string2array(['status' => 0,
			    'value' => 'id参数不完整',
				'jifen' => '',]);
	        return dr_return_data(0, $msg);
	    }
	
	    $table = $tablename.'_bug';
	    if (!$this->db->tableExists($table) ) {
	        return dr_return_data(0, dr_lang('没有进度数据库表[%s]', $dirname));
	    }
		
		
		if ($this->index['uid'] != $this->uid) {
			
			$msg = dr_string2array(['status' => 0,
			    'value' => '您不是圈主，无权操作',
				'jifen' => '',]);
			return dr_return_data(0, $msg, $c);
		}
	
	    $bug = $this->db->table($table)->where('cid', $id)->where('leixing', 2)->where('uid', $this->uid)->get()->getRowArray();
	    if ($bug) {
	        // 取消进度,我们就删除它
			
			$msg = dr_string2array(['status' => 0,
			    'value' => '取消排期',
				'jifen' => '',]);
	        $this->db->table($table)->where('cid', $id)->where('leixing', 2)->delete();
	
	    } else {
			//进度
			$msg = dr_string2array(['status' => 1,
			    'value' => '开启排期',
				'jifen' => '',]);
	        $this->db->table($table)->insert(array(
	            'cid' => $id,
	            'uid' => $this->uid,
				'leixing' => 2,
	            'inputtime' => SYS_TIME
	        ));
	
	    }
	
	    // 更新缓存
	    //$c = $this->db->table($tablename.'_form_son_zan')->where('cid', $id)->countAllResults();
	    //$this->db->table($tablename.'_form_son')->where('id', $id)->set('zan', $c)->update();
	    \Phpcmf\Service::M('cache')->update_data_cache();
	
	    // 返回结果
	    return dr_return_data(1, $msg, $c);
	
	}
	/*BUG进度-开发*/
	public function bugkaifa($tablename, $dirname) {
	
	    $id = (int)\Phpcmf\Service::L('input')->get('id');
		$quanid = (int)\Phpcmf\Service::L('input')->get('quanid');
		$this->index = $this->db->table($tablename)->where('id', $quanid)->get()->getRowArray();
		//dr_debug('$indexuid', $this->index);
	    if (!$this->uid) {
			$msg = dr_string2array(['status' => 0,
			    'value' => '还没有登录',
				'jifen' => '',]);
	        return dr_return_data(0, $msg);
	    } elseif (!$id) {
			$msg = dr_string2array(['status' => 0,
			    'value' => 'id参数不完整',
				'jifen' => '',]);
	        return dr_return_data(0, $msg);
	    }
	
	    $table = $tablename.'_bug';
	    if (!$this->db->tableExists($table) ) {
	        return dr_return_data(0, dr_lang('没有进度数据库表[%s]', $dirname));
	    }
		
		
		if ($this->index['uid'] != $this->uid) {
			
			$msg = dr_string2array(['status' => 0,
			    'value' => '您不是圈主，无权操作',
				'jifen' => '',]);
			return dr_return_data(0, $msg, $c);
		}
	
	    $bug = $this->db->table($table)->where('cid', $id)->where('leixing', 3)->where('uid', $this->uid)->get()->getRowArray();
	    if ($bug) {
	        // 取消进度,我们就删除它
			
			$msg = dr_string2array(['status' => 0,
			    'value' => '取消开发',
				'jifen' => '',]);
	        $this->db->table($table)->where('cid', $id)->where('leixing', 3)->delete();
	
	    } else {
			//进度
			$msg = dr_string2array(['status' => 1,
			    'value' => '开启开发',
				'jifen' => '',]);
	        $this->db->table($table)->insert(array(
	            'cid' => $id,
	            'uid' => $this->uid,
				'leixing' => 3,
	            'inputtime' => SYS_TIME
	        ));
	
	    }
	
	    // 更新缓存
	    //$c = $this->db->table($tablename.'_form_son_zan')->where('cid', $id)->countAllResults();
	    //$this->db->table($tablename.'_form_son')->where('id', $id)->set('zan', $c)->update();
	    \Phpcmf\Service::M('cache')->update_data_cache();
	
	    // 返回结果
	    return dr_return_data(1, $msg, $c);
	
	}
	/*BUG进度-完成*/
	public function bugwancheng($tablename, $dirname) {
	
	    $id = (int)\Phpcmf\Service::L('input')->get('id');
		$quanid = (int)\Phpcmf\Service::L('input')->get('quanid');
		$this->index = $this->db->table($tablename)->where('id', $quanid)->get()->getRowArray();
		//dr_debug('$indexuid', $this->index);
	    if (!$this->uid) {
			$msg = dr_string2array(['status' => 0,
			    'value' => '还没有登录',
				'jifen' => '',]);
	        return dr_return_data(0, $msg);
	    } elseif (!$id) {
			$msg = dr_string2array(['status' => 0,
			    'value' => 'id参数不完整',
				'jifen' => '',]);
	        return dr_return_data(0, $msg);
	    }
	
	    $table = $tablename.'_bug';
	    if (!$this->db->tableExists($table) ) {
	        return dr_return_data(0, dr_lang('没有进度数据库表[%s]', $dirname));
	    }
		
		
		if ($this->index['uid'] != $this->uid) {
			
			$msg = dr_string2array(['status' => 0,
			    'value' => '您不是圈主，无权操作',
				'jifen' => '',]);
			return dr_return_data(0, $msg, $c);
		}
	
	    $bug = $this->db->table($table)->where('cid', $id)->where('leixing', 4)->where('uid', $this->uid)->get()->getRowArray();
	    if ($bug) {
	        // 取消进度,我们就删除它
			
			$msg = dr_string2array(['status' => 0,
			    'value' => '取消完成',
				'jifen' => '',]);
	        $this->db->table($table)->where('cid', $id)->where('leixing', 4)->delete();
	
	    } else {
			//进度
			$msg = dr_string2array(['status' => 1,
			    'value' => '完成开发',
				'jifen' => '',]);
	        $this->db->table($table)->insert(array(
	            'cid' => $id,
	            'uid' => $this->uid,
				'leixing' => 4,
	            'inputtime' => SYS_TIME
	        ));
	
	    }
	
	    // 更新缓存
	    //$c = $this->db->table($tablename.'_form_son_zan')->where('cid', $id)->countAllResults();
	    //$this->db->table($tablename.'_form_son')->where('id', $id)->set('zan', $c)->update();
	    \Phpcmf\Service::M('cache')->update_data_cache();
	
	    // 返回结果
	    return dr_return_data(1, $msg, $c);
	
	}
	/*PK方*/
	public function pk($tablename, $pkfang, $biao, $dirname) {
	
	    $id = (int)\Phpcmf\Service::L('input')->get('id');
		$pkfang = (int)\Phpcmf\Service::L('input')->get('pkfang');
		$quanid = (int)\Phpcmf\Service::L('input')->get('quanid');
		$this->index = $this->db->table($tablename)->where('id', $quanid)->get()->getRowArray();
		//dr_debug('$indexuid', $this->index);
	    if (!$this->uid) {
			$msg = dr_string2array(['status' => 0,
			    'value' => '还没有登录',
				'jifen' => '',]);
	        return dr_return_data(0, $msg);
	    } elseif (!$id) {
			$msg = dr_string2array(['status' => 0,
			    'value' => 'id参数不完整',
				'jifen' => '',]);
	        return dr_return_data(0, $msg);
	    }
	
	    $table = $tablename.'_form_son_pk';
	    if (!$this->db->tableExists($table) ) {
	        return dr_return_data(0, dr_lang('没有PK数据库表[%s]', $dirname));
	    }
		
		/*if ($this->index['uid'] != $this->uid) {
			
			$msg = dr_string2array(['status' => 0,
			    'value' => '您不是圈主，无权操作',
				'jifen' => '',]);
			return dr_return_data(0, $msg, $c);
		}*/
		//奖励
		$pkjianglis = $this->db->table($tablename.'_form_son')->where('id', $id)->get()->getRowArray();
		// 消费余额
		// $xiaofeiesum = selectSum($pkrmbhe['jianglirmb'], 'num'); ->where('cid', $id)->selectSum('jianglirmb')->get()->getRowArray();
		$xiaofeiesum = $this->db->table($table)->where('cid', $id)->selectSum('jianglirmb')->get()->getRowArray();
		// 消费积分
		$xiaofeiejifensum = $this->db->table($table)->where('cid', $id)->selectSum('jiangli')->get()->getRowArray();
		//人民币发值
		$pkrmbzhi = $this->index['xiaofeie'] - $xiaofeiesum['jianglirmb'];
		//积分值
		$pkjifenzhi = $this->index['xiaofeie'] - $xiaofeiejifensum['jiangli'];
		
		//判断PK审核
		if($pkjianglis['pkshenhe']==1){
			$pkjiangli = 0;
			$pkjianglirmb = 0;
			$pkshenhe = 1;
		} else {
			if($pkjianglis['pkjiangli'] ==2) {
				//人民币
				if($pkjianglis['jlrmb'] <= $pkrmbzhi) {
					if ($pkjianglis['jlrmb'] >0) {
						$pkjiangli = 0;
						$pkjianglirmb = $pkjianglis['jlrmb'];
						$pkshenhe = 0;
					}  else {
						$pkjiangli = 0;
						$pkjianglirmb = 0;
						$pkshenhe = 0;
					}
				} else {
					$pkjiangli = 0;
					$pkjianglirmb = 0;
					$pkshenhe = 0;
				}
				
			} elseif ($pkjianglis['pkjiangli'] ==1) {
				if($pkjianglis['jianglijifen'] <= $pkjifenzhi) {
					if ($pkjianglis['jianglijifen'] >0) {
						$pkjiangli = $pkjianglis['jianglijifen'];
						$pkjianglirmb = 0;
						$pkshenhe = 0;
					} else {
						$pkjiangli = 0;
						$pkjianglirmb = 0;
						$pkshenhe = 0;
					}
				} else {
					$pkjiangli = 0;
					$pkjianglirmb = 0;
					$pkshenhe = 0;
				}
			} else {
				$pkjiangli = 0;
				$pkjianglirmb = 0;
				$pkshenhe = 0;
			}
		}
		//PK人民币总和
		$pkrmbhe = $this->db->table($table)->where('cid', $id)->where('pkshenhe', 0)->countAllResults();
		
		
		//$jiangli = 0;
	    //蓝方
		if($pkfang == 1) {
			$lanfang = $this->db->table($table)->where('cid', $id)->where('pkfang', 1)->where('uid', $this->uid)->get()->getRowArray();
			if ($lanfang) {
			    // 取消,就删除数据
				/*$msg = dr_string2array(['status' => 0,
				    'value' => '取消完成',
					'jifen' => '',]);
			    $this->db->table($table)->where('cid', $id)->where('pkfang', 1)->where('uid', $this->uid)->delete();*/
				
			} else {
				//pk添加数据
				$msg = dr_string2array(['status' => 1,
				    'value' => '支持成功',
					'jifen' => '',]);
				//添加数据
			    $this->db->table($table)->insert(array(
			        'cid' => $id,
			        'uid' => $this->uid,
					'pkfang' => 1,
					'jiangli' => $pkjiangli,
					'jianglirmb' => $pkjianglirmb,
					'pkshenhe' => $pkshenhe,
			        'inputtime' => SYS_TIME
			    ));
				
				
				
				//PK总数
				$pktongji = $this->db->table($table)->where('cid', $id)->where('pkshenhe', 0)->countAllResults();
				//蓝方统计
				$lanfangtongji = $this->db->table($table)->where('cid', $id)->where('pkfang', 1)->where('pkshenhe', 0)->countAllResults();
				//红方统计
				$hongfangtongji = $this->db->table($table)->where('cid', $id)->where('pkfang', 2)->where('pkshenhe', 0)->countAllResults();
				//蓝方比例
				$pklanbili =($lanfangtongji / $pktongji)*100;
				//红方比例
				$pkhongbilis = 100 - $pklanbili;
				if ($pklanbili >= 80) {
					$pklanbili = 80;
					$pkhongbili = 20;
				} else {
					$pklanbili = ($lanfangtongji / $pktongji)*100;
					$pkhongbili = $pkhongbilis;
				}
				//统计更新数据
				$pkshuxing = [
					'lanfangtongji' => $lanfangtongji, //蓝方统计
					'lanfangbili' => $pklanbili, //蓝方比例
					'hongfangtongji' => $hongfangtongji, //红方统计
					'hongfangbili' => $pkhongbili, //红方比例
					'pktongji' => $pktongji, //pk总数
					];
				$this->db->table($tablename.'_form_son')->where('id', $id)->update([
					'pk_shuxing' => dr_array2string($pkshuxing)
					]);
				//$this->db->table($tablename.'_form_son')->where('id', $id)->update(['jindu' => 0]);
			}
		} else {
			$hongfang = $this->db->table($table)->where('cid', $id)->where('pkfang', 2)->where('uid', $this->uid)->get()->getRowArray();
			if ($hongfang) {
			    // 取消,就删除数据
				$msg = dr_string2array(['status' => 0,
				    'value' => '取消完成',
					'jifen' => '',]);
			    $this->db->table($table)->where('cid', $id)->where('pkfang', 2)->where('uid', $this->uid)->delete();
				
			} else {
				//pk添加数据
				$msg = dr_string2array(['status' => 1,
				    'value' => '支持成功',
					'jifen' => '',]);
			    $this->db->table($table)->insert(array(
			        'cid' => $id,
			        'uid' => $this->uid,
					'pkfang' => 2,
					'jiangli' =>$pkjiangli,
					'jianglirmb' => $pkjianglirmb,
					'pkshenhe' => $pkshenhe,
			        'inputtime' => SYS_TIME
			    ));
				//PK总数
				$pktongji = $this->db->table($table)->where('cid', $id)->countAllResults();
				//蓝方统计
				$lanfangtongji = $this->db->table($table)->where('cid', $id)->where('pkfang', 1)->countAllResults();
				//红方统计
				$hongfangtongji = $this->db->table($table)->where('cid', $id)->where('pkfang', 2)->countAllResults();
				//蓝方比例
				$pklanbili =($lanfangtongji / $pktongji)*100;
				//红方比例
				$pkhongbilis = 100 - $pklanbili;
				if ($pkhongbilis >= 80) {
					$pklanbili = 20;
					$pkhongbili = 80;
				} else {
					$pklanbili = ($lanfangtongji / $pktongji)*100;
					$pkhongbili = $pkhongbilis;
				}
				//统计更新数据
				$pkshuxing = [
					'lanfangtongji' => $lanfangtongji, //蓝方统计
					'lanfangbili' => $pklanbili, //蓝方比例
					'hongfangtongji' => $hongfangtongji, //红方统计
					'hongfangbili' => $pkhongbili, //红方比例
					'pktongji' => $pktongji, //pk总数
					];
				$this->db->table($tablename.'_form_son')->where('id', $id)->update([
					'pk_shuxing' => dr_array2string($pkshuxing)
					]);
			}
		}
		//网址
		$urls = '/index.php?s='.$biao.'&c=son&id='.$pkjianglis['id'];
		//标题
		if($pkjianglis['title']){
			$pktitle = $pkjianglis['title'];
		} else {
			$pktitle = dr_strcut(dr_clearhtml($pkjianglis['neirong']), 20);
		}
		
		
	    //不需要核对，直接增加积分
	    if ($pkshenhe == 0){
			if($pkjianglis['pkjiangli'] == 2) {
				
				if($xiaofeiesum['jianglirmb'] <= $pkrmbzhi) {
					if($pkjianglirmb > 0){ //人民币大于0才执行添加
						\Phpcmf\Service::M('member')->add_money($this->uid, $pkjianglirmb);
						//添加人民币记录
						\Phpcmf\Service::M('pay')->add_paylog([
							'uid' => $this->uid,
							'username' => '',
							'touid' => $pkjianglis['uid'],
							'tousername' => '',
							'mid' => 'system',
							'title' => '《'.$pktitle.'》PK奖励',
							'value' => $pkjianglirmb,
							'type' => finecms,
							'status' => 1,
							'result' => 'PK奖励',
							'paytime' => SYS_TIME,
							'inputtime' => SYS_TIME,
						]);
						//减去贴主费用
						\Phpcmf\Service::M('member')->add_money($pkjianglis['uid'], -$pkjianglirmb);
						//添加减去贴主人民币记录
						\Phpcmf\Service::M('pay')->add_paylog([
							'uid' => $pkjianglis['uid'],
							'username' => '',
							'touid' => $this->uid,
							'tousername' => '',
							'mid' => 'system',
							'title' => '《'.$pktitle.'》PK奖励扣除费用',
							'value' => -$pkjianglirmb,
							'type' => finecms,
							'status' => 1,
							'result' => 'PK奖励扣除',
							'paytime' => SYS_TIME,
							'inputtime' => SYS_TIME,
						]);
					}
				}
			} elseif ($pkjianglis['pkjiangli'] ==1){
				if($xiaofeiejifensum['jiangli'] <= $pkjifenzhi) {
					if($pkjiangli > 0){ //积分大于0才执行添加
						\Phpcmf\Service::M('member')->add_score($this->uid, $pkjiangli, $note = '', $urls, $mark = '', $count = 0);
						\Phpcmf\Service::M('member')->add_score($pkjianglis['uid'], -$pkjiangli, $note = '', $urls, $mark = '', $count = 0);
					}
				}
			}
	    	
			
	    }
	
	    // 更新缓存
	    //$c = $this->db->table($tablename.'_form_son_zan')->where('cid', $id)->countAllResults();
	    //$this->db->table($tablename.'_form_son')->where('id', $id)->set('zan', $c)->update();
	    \Phpcmf\Service::M('cache')->update_data_cache();
	
	    // 返回结果
	    return dr_return_data(1, $msg, $c);
	
	}
	/*PK不通过*/
	public function pkbutong($tablename, $pkfang, $biao, $dirname) {
		$id = (int)\Phpcmf\Service::L('input')->get('id');
		$tieid = (int)\Phpcmf\Service::L('input')->get('tieid');
		$quanid = (int)\Phpcmf\Service::L('input')->get('quanid');
		$table = $tablename.'_form_son_pk';
		
		$this->index = $this->db->table($tablename.'_form_son')->where('id', $tieid)->get()->getRowArray();
		if($this->index['uid'] != $this->uid) {
			$msg = dr_string2array(['status' => 0,
			    'value' => '您没有权限操作',
				'jifen' => '',]);
			return dr_return_data(0, $msg);
		}
		$this->db->table($table)->where('id', $id)->update([
			'pkshenhe' => 3,
			]);
		$msg = dr_string2array(['status' => 1,
		    'value' => '操作成功，PK不通过',
			'jifen' => '',]);
		// 返回结果
		return dr_return_data(1, $msg, $c);
	}
	/*PK删除*/
	public function pkshanchu($tablename, $pkfang, $biao, $dirname) {
		$id = (int)\Phpcmf\Service::L('input')->get('id');
		$tieid = (int)\Phpcmf\Service::L('input')->get('tieid');
		$quanid = (int)\Phpcmf\Service::L('input')->get('quanid');
		$table = $tablename.'_form_son_pk';
		
		$this->index = $this->db->table($tablename.'_form_son')->where('id', $tieid)->get()->getRowArray();
		dr_debug('a123', $this->index['uid'].'----'.$tablename);
		if($this->index['uid'] != $this->uid) {
			$msg = dr_string2array(['status' => 0,
			    'value' => '您没有权限删除'.$tablename.'-uid'.$this->index['uid'].'--'.$id,
				'jifen' => '',]);
			return dr_return_data(0, $msg);
		}
		
		$this->db->table($table)->where('id', intval($id))->delete();
		$msg = dr_string2array(['status' => 1,
		    'value' => '已经删除成功',
			'jifen' => '',]);
		// 返回结果
		return dr_return_data(1, $msg, $c);
	}
	
	/*PK通过*/
	public function pktongguo($tablename, $pkfang, $biao, $dirname) {
		$id = (int)\Phpcmf\Service::L('input')->get('id');
		$tieid = (int)\Phpcmf\Service::L('input')->get('tieid');
		$uid = (int)\Phpcmf\Service::L('input')->get('uid');
		$table = $tablename.'_form_son_pk';
		$tablecomment = $tablename.'_form_son_comment';
		$this->index = $this->db->table($tablename.'_form_son')->where('id', $tieid)->get()->getRowArray();
		$pkshuju = $this->db->table($table)->where('cid', $tieid)->where('uid', $uid)->get()->getRowArray();
		if($this->index['pkjiangli'] == 1){
			if($pkshuju['jiangli'] > 0 || $pkshuju['pkshenhe'] == 0) {
				$msg = dr_string2array(['status' => 1,
				    'value' => '已经领取过奖励',
					'jifen' => '',]);
				return dr_return_data(1, $msg);
			}
		} elseif ($this->index['pkjiangli'] == 2 || $pkshuju['pkshenhe'] == 0){
			if($pkshuju['jianglirmb'] > 0) {
				$msg = dr_string2array(['status' => 1,
				    'value' => '已经领取过奖励',
					'jifen' => '',]);
				return dr_return_data(1, $msg);
			}
		}
		
		//网址
		$urls = '/index.php?s='.$biao.'&c=son&id='.$tieid;
		//标题
		if($this->index['title']){
			$pktitle = $this->index['title'];
		} else {
			$pktitle = dr_strcut(dr_clearhtml($this->index['neirong']), 20);
		}
		
		if($this->index['uid'] != $this->uid) {
			$msg = dr_string2array(['status' => 0,
			    'value' => '您没有权限操作',
				'jifen' => '',]);
			return dr_return_data(0, $msg);
		}
		if($this->index['pkjiangli']==1) {
			$jianglizhi = $this->index['jianglijifen'];
			$jianglirmbzhi = 0;
		} elseif ($this->index['pkjiangli']==2){
			$jianglizhi = 0;
			$jianglirmbzhi = $this->index['jlrmb'];
		}
		
		// 消费余额
		$xiaofeiesum = $this->db->table($table)->where('cid', $tieid)->selectSum('jianglirmb')->get()->getRowArray();
		// 消费积分
		$xiaofeiejifensum = $this->db->table($table)->where('cid', $tieid)->selectSum('jiangli')->get()->getRowArray();
		//人民币发值
		$pkrmbzhi = $this->index['xiaofeie'] - $xiaofeiesum['jianglirmb'];
		//积分值
		$pkjifenzhi = $this->index['xiaofeie'] - $xiaofeiejifensum['jiangli'];
		//判断奖励方式1为积分。2为人民币
		if($this->index['pkjiangli']==1) {
			//奖励积分
			dr_debug('文件名称', '总积分'.$pkjifenzhi.'原值'.$this->index['jianglijifen']);
			if($pkjifenzhi >= $this->index['jianglijifen']){
				if($this->index['jianglijifen'] > 0) {
					$this->db->table($table)->where('id', $id)->where('uid', $uid)->update([
						'pkshenhe' => 0,
						'jiangli' => $jianglizhi,
						'jianglirmb' => $jianglirmbzhi,
						]);
					$this->db->table($tablecomment)->where('cid', $tieid)->where('uid', $uid)->where('inputtime', $pkshuju['inputtime'])->update([
						'status' => 1,
						]);
					\Phpcmf\Service::M('member')->add_score($uid, $this->index['jianglijifen'], $note = $pktitle.'PK奖励', $urls, $mark = '', $count = 0);
					\Phpcmf\Service::M('member')->add_score($this->index['uid'], -$this->index['jianglijifen'], $note = $pktitle.'PK扣除', $urls, $mark = '', $count = 0);
				}
			} else {
				$this->db->table($table)->where('id', $id)->where('uid', $uid)->update([
					'pkshenhe' => 0,
					'jiangli' => 0,
					'jianglirmb' => 0,
					]);
				$this->db->table($tablecomment)->where('cid', $tieid)->where('uid', $uid)->where('inputtime', $pkshuju['inputtime'])->update([
					'status' => 1,
					]);
			}
			
		} elseif ($this->index['pkjiangli']==2){
			//奖励人民币
			if($this->index['jlrmb'] <= $pkrmbzhi){
				if($this->index['jlrmb'] > 0) {
					$this->db->table($table)->where('id', $id)->where('uid', $uid)->update([
						'pkshenhe' => 0,
						'jiangli' => $jianglizhi,
						'jianglirmb' => $jianglirmbzhi,
						]);
					$this->db->table($tablecomment)->where('cid', $tieid)->where('uid', $uid)->where('inputtime', $pkshuju['inputtime'])->update([
						'status' => 1,
						]);
					\Phpcmf\Service::M('member')->add_money($this->uid, $this->index['jlrmb']);
					//添加人民币记录
					\Phpcmf\Service::M('pay')->add_paylog([
						'uid' => $uid,
						'username' => '',
						'touid' => $this->index['uid'],
						'tousername' => '',
						'mid' => 'system',
						'title' => '《'.$pktitle.'》PK奖励',
						'value' => $this->index['jlrmb'],
						'type' => finecms,
						'status' => 1,
						'result' => 'PK奖励',
						'paytime' => SYS_TIME,
						'inputtime' => SYS_TIME,
					]);
					//减去贴主费用
					\Phpcmf\Service::M('member')->add_money($this->index['uid'], -$this->index['jlrmb']);
					//添加减去贴主人民币记录
					\Phpcmf\Service::M('pay')->add_paylog([
						'uid' => $this->index['uid'],
						'username' => '',
						'touid' => $uid,
						'tousername' => '',
						'mid' => 'system',
						'title' => '《'.$pktitle.'》PK奖励扣除费用',
						'value' => -$this->index['jlrmb'],
						'type' => finecms,
						'status' => 1,
						'result' => 'PK奖励扣除',
						'paytime' => SYS_TIME,
						'inputtime' => SYS_TIME,
					]);
				}
			} else {
				$this->db->table($table)->where('id', $id)->where('uid', $uid)->update([
					'pkshenhe' => 0,
					'jiangli' => $jianglizhi,
					'jianglirmb' => $jianglirmbzhi,
					]);
				$this->db->table($tablecomment)->where('cid', $tieid)->where('uid', $uid)->where('inputtime', $pkshuju['inputtime'])->update([
					'status' => 1,
					]);
			}
		} elseif ($this->index['pkjiangli']== 0){
			$this->db->table($table)->where('id', $id)->where('uid', $uid)->update([
				'pkshenhe' => 0,
				'jiangli' => 0,
				'jianglirmb' => 0,
				]);
			$this->db->table($tablecomment)->where('cid', $tieid)->where('uid', $uid)->where('inputtime', $pkshuju['inputtime'])->update([
				'status' => 1,
				]);
		}
		$msg = dr_string2array(['status' => 1,
		    'value' => '操作成功已经通过',
			'jifen' => '',]);
		// 返回结果
		return dr_return_data(1, $msg, $c);
	}
	/*出租*/
	public function chuzu($tablename, $chuzu, $biao, $dirname) {
	
	    $id = (int)\Phpcmf\Service::L('input')->get('id');
		$quanid = (int)\Phpcmf\Service::L('input')->get('quanid');
		$this->index = $this->db->table($tablename.'_form_son')->where('id', $id)->get()->getRowArray();
		//dr_debug('$indexuid', $this->index);
	    if (!$this->uid) {
			$msg = dr_string2array(['status' => 0,
			    'value' => '还没有登录',
				'jifen' => '',]);
	        return dr_return_data(0, $msg);
	    } elseif (!$id) {
			$msg = dr_string2array(['status' => 0,
			    'value' => 'id参数不完整',
				'jifen' => '',]);
	        return dr_return_data(0, $msg);
	    }
	
	    $table = $tablename.'_chuzu';
	    if (!$this->db->tableExists($table) ) {
	        return dr_return_data(0, dr_lang('没有进度数据库表[%s]', $dirname));
	    }
		
		
		if ($this->index['uid'] != $this->uid) {
			
			$msg = dr_string2array(['status' => 0,
			    'value' => '您不是贴主，无权操作',
				'jifen' => '',]);
			return dr_return_data(0, $msg, $c);
		}
	
	    $bug = $this->db->table($table)->where('cid', $id)->where('leixing', 1)->where('uid', $this->uid)->get()->getRowArray();
	    if ($bug) {
	        // 取消进度,我们就删除它
			
			$msg = dr_string2array(['status' => 0,
			    'value' => '取消排期',
				'jifen' => '',]);
	        $this->db->table($table)->where('cid', $id)->where('leixing', 1)->delete();
	
	    } else {
			//进度
			$msg = dr_string2array(['status' => 1,
			    'value' => '已租啦',
				'jifen' => '',]);
	        $this->db->table($table)->insert(array(
	            'cid' => $id,
	            'uid' => $this->uid,
				'leixing' => 1,
	            'inputtime' => SYS_TIME
	        ));
	
	    }
	
	    // 更新缓存
	    //$c = $this->db->table($tablename.'_form_son_zan')->where('cid', $id)->countAllResults();
	    //$this->db->table($tablename.'_form_son')->where('id', $id)->set('zan', $c)->update();
	    \Phpcmf\Service::M('cache')->update_data_cache();
	
	    // 返回结果
	    return dr_return_data(1, $msg, $c);
	
	}
	/*求租*/
	public function qiuzu($tablename, $qiuzu, $biao, $dirname) {
	
	    $id = (int)\Phpcmf\Service::L('input')->get('id');
		$quanid = (int)\Phpcmf\Service::L('input')->get('quanid');
		$this->index = $this->db->table($tablename.'_form_son')->where('id', $id)->get()->getRowArray();
		//dr_debug('$indexuid', $this->index);
	    if (!$this->uid) {
			$msg = dr_string2array(['status' => 0,
			    'value' => '还没有登录',
				'jifen' => '',]);
	        return dr_return_data(0, $msg);
	    } elseif (!$id) {
			$msg = dr_string2array(['status' => 0,
			    'value' => 'id参数不完整',
				'jifen' => '',]);
	        return dr_return_data(0, $msg);
	    }
	
	    $table = $tablename.'_qiuzu';
	    if (!$this->db->tableExists($table) ) {
	        return dr_return_data(0, dr_lang('没有进度数据库表[%s]', $dirname));
	    }
		
		
		if ($this->index['uid'] != $this->uid) {
			
			$msg = dr_string2array(['status' => 0,
			    'value' => '您不是贴主，无权操作',
				'jifen' => '',]);
			return dr_return_data(0, $msg, $c);
		}
	
	    $bug = $this->db->table($table)->where('cid', $id)->where('leixing', 1)->where('uid', $this->uid)->get()->getRowArray();
	    if ($bug) {
	        // 取消进度,我们就删除它
			
			$msg = dr_string2array(['status' => 0,
			    'value' => '取消排期',
				'jifen' => '',]);
	        $this->db->table($table)->where('cid', $id)->where('leixing', 1)->delete();
	
	    } else {
			//进度
			$msg = dr_string2array(['status' => 1,
			    'value' => '租到啦',
				'jifen' => '',]);
	        $this->db->table($table)->insert(array(
	            'cid' => $id,
	            'uid' => $this->uid,
				'leixing' => 1,
	            'inputtime' => SYS_TIME
	        ));
	
	    }
	
	    // 更新缓存
	    //$c = $this->db->table($tablename.'_form_son_zan')->where('cid', $id)->countAllResults();
	    //$this->db->table($tablename.'_form_son')->where('id', $id)->set('zan', $c)->update();
	    \Phpcmf\Service::M('cache')->update_data_cache();
	
	    // 返回结果
	    return dr_return_data(1, $msg, $c);
	
	}
	/*招聘*/
	public function zhaopin($tablename, $zhaopin, $biao, $dirname) {
	
	    $id = (int)\Phpcmf\Service::L('input')->get('id');
		$quanid = (int)\Phpcmf\Service::L('input')->get('quanid');
		$this->index = $this->db->table($tablename.'_form_son')->where('id', $id)->get()->getRowArray();
		//dr_debug('$indexuid', $this->index);
	    if (!$this->uid) {
			$msg = dr_string2array(['status' => 0,
			    'value' => '还没有登录',
				'jifen' => '',]);
	        return dr_return_data(0, $msg);
	    } elseif (!$id) {
			$msg = dr_string2array(['status' => 0,
			    'value' => 'id参数不完整',
				'jifen' => '',]);
	        return dr_return_data(0, $msg);
	    }
	
	    $table = $tablename.'_zhaopin';
	    if (!$this->db->tableExists($table) ) {
	        return dr_return_data(0, dr_lang('没有进度数据库表[%s]', $dirname));
	    }
		
		
		if ($this->index['uid'] != $this->uid) {
			
			$msg = dr_string2array(['status' => 0,
			    'value' => '您不是贴主，无权操作',
				'jifen' => '',]);
			return dr_return_data(0, $msg, $c);
		}
	
	    $bug = $this->db->table($table)->where('cid', $id)->where('leixing', 1)->where('uid', $this->uid)->get()->getRowArray();
	    if ($bug) {
	        // 取消进度,我们就删除它
			
			$msg = dr_string2array(['status' => 0,
			    'value' => '取消排期',
				'jifen' => '',]);
	        $this->db->table($table)->where('cid', $id)->where('leixing', 1)->delete();
	
	    } else {
			//进度
			$msg = dr_string2array(['status' => 1,
			    'value' => '已聘到啦',
				'jifen' => '',]);
	        $this->db->table($table)->insert(array(
	            'cid' => $id,
	            'uid' => $this->uid,
				'leixing' => 1,
	            'inputtime' => SYS_TIME
	        ));
	
	    }
	
	    // 更新缓存
	    //$c = $this->db->table($tablename.'_form_son_zan')->where('cid', $id)->countAllResults();
	    //$this->db->table($tablename.'_form_son')->where('id', $id)->set('zan', $c)->update();
	    \Phpcmf\Service::M('cache')->update_data_cache();
	
	    // 返回结果
	    return dr_return_data(1, $msg, $c);
	
	}
	/*求职*/
	public function qiuzhi($tablename, $qiuzhi, $biao, $dirname) {
	
	    $id = (int)\Phpcmf\Service::L('input')->get('id');
		$quanid = (int)\Phpcmf\Service::L('input')->get('quanid');
		$this->index = $this->db->table($tablename.'_form_son')->where('id', $id)->get()->getRowArray();
		//dr_debug('$indexuid', $this->index);
	    if (!$this->uid) {
			$msg = dr_string2array(['status' => 0,
			    'value' => '还没有登录',
				'jifen' => '',]);
	        return dr_return_data(0, $msg);
	    } elseif (!$id) {
			$msg = dr_string2array(['status' => 0,
			    'value' => 'id参数不完整',
				'jifen' => '',]);
	        return dr_return_data(0, $msg);
	    }
	
	    $table = $tablename.'_qiuzhi';
	    if (!$this->db->tableExists($table) ) {
	        return dr_return_data(0, dr_lang('没有进度数据库表[%s]', $dirname));
	    }
		
		
		if ($this->index['uid'] != $this->uid) {
			
			$msg = dr_string2array(['status' => 0,
			    'value' => '您不是贴主，无权操作',
				'jifen' => '',]);
			return dr_return_data(0, $msg, $c);
		}
	
	    $bug = $this->db->table($table)->where('cid', $id)->where('leixing', 1)->where('uid', $this->uid)->get()->getRowArray();
	    if ($bug) {
	        // 取消进度,我们就删除它
			
			$msg = dr_string2array(['status' => 0,
			    'value' => '取消排期',
				'jifen' => '',]);
	        $this->db->table($table)->where('cid', $id)->where('leixing', 1)->delete();
	
	    } else {
			//进度
			$msg = dr_string2array(['status' => 1,
			    'value' => '已找到工作',
				'jifen' => '',]);
	        $this->db->table($table)->insert(array(
	            'cid' => $id,
	            'uid' => $this->uid,
				'leixing' => 1,
	            'inputtime' => SYS_TIME
	        ));
	
	    }
	
	    // 更新缓存
	    //$c = $this->db->table($tablename.'_form_son_zan')->where('cid', $id)->countAllResults();
	    //$this->db->table($tablename.'_form_son')->where('id', $id)->set('zan', $c)->update();
	    \Phpcmf\Service::M('cache')->update_data_cache();
	
	    // 返回结果
	    return dr_return_data(1, $msg, $c);
	
	}
	/*投票*/
	public function toupiao($tablename, $value, $biao, $dirname) {
	
		$id = (int)\Phpcmf\Service::L('input')->get('id');
		$value = (int)\Phpcmf\Service::L('input')->get('value');
		$this->index = $this->db->table($tablename.'_form_son')->where('id', $id)->get()->getRowArray();
		if ($this->index['title']) {
			$datatitle = $this->index['title'];
		} else {
			$datatitle = dr_strcut(dr_clearhtml($this->index['neirong']), 70);
		}
		//dr_debug('$indexuid', $this->index);
		if (!$this->uid) {
			$msg = dr_string2array(['status' => 0,
				'value' => '还没有登录',
				'jifen' => '',]);
			return dr_return_data(0, $msg);
		} elseif (!$id) {
			$msg = dr_string2array(['status' => 0,
				'value' => 'id参数不完整',
				'jifen' => '',]);
			return dr_return_data(0, $msg);
		}
	
		$table = $tablename.'_toupiaobiao';
		if (!$this->db->tableExists($table) ) {
			return dr_return_data(0, dr_lang('没有进度数据库表[%s]', $dirname));
		}
		
		
		/*if ($this->index['uid'] != $this->uid) {
			
			$msg = dr_string2array(['status' => 0,
				'value' => '您不是贴主，无权操作',
				'jifen' => '',]);
			return dr_return_data(0, $msg, $c);
		}*/
		if ($this->index['toupiaojl'] == '1'){
			//待开发
			$rmb = 0; //人民币
			$jianglijifen = 0; //积分
		} elseif ($this->index['toupiaojl'] == '2') {
			//积分奖励
			if ($this->member['score'] > $this->index['tpjianglijifen']) {
				/*$msg = dr_string2array(['status' => 0,
					'value' => '您的'.SITE_SCORE.'是 '.$this->member['score'].'已经不足奖励',
					'jifen' => '',]);*/
				
				//return dr_return_data(0, $msg);
				$jifen = '奖励'.$this->index['tpjianglijifen'].SITE_SCORE;
				$jianglijifen = $this->index['tpjianglijifen']; //积分
				$rmb = 0; //人民币
			} else {
				$jifen = '感谢参与';
				$jianglijifen = 0;
			}
			$jianqujiangli = '奖励'.$this->index['tpjianglijifen'].SITE_SCORE;
			
		} elseif ($this->index['toupiaojl'] == '3') {
			//人民币奖励
			if ($this->member['money'] > $this->index['tpjlrmb']) {
				/*$msg = dr_string2array(['status' => 0,
					'value' => '您的余额是 '.$this->member['money'].'已经不足奖励',
					'jifen' => '',]);
				return dr_return_data(0, $msg);*/
				$jianglijifen = 0; //积分
				$rmb = $this->index['tpjlrmb']; //人民币
				$jianqujiangli = '奖励'.$this->index['tpjlrmb'].'人民币';
			} else {
				$jifen = '感谢参与';
				$jianglijifen = 0;
			}
		}
		//单选模式
		if($this->index['toupiaomoshi'] == '1') {
			$toupiao = $this->db->table($table)->where('cid', $id)->where('leixing', 1)->where('uid', $this->uid)->get()->getRowArray();
			
			if ($toupiao) {
				// 取消投票,我们就删除它
				if ($this->index['qxtps']==2){
					$msg = dr_string2array(['status' => 1,
						'value' => '您已经投票',
						'jifen' => '',]);
				} else {
					
					$quxiaotoupiao = $this->db->table($table)->where('cid', $id)->where('uid', $this->uid)->where('toupiaoid',$value)->get()->getRowArray();
					if(!$quxiaotoupiao){
						
						$msg = dr_string2array(['status' => 1,
							'value' => '您已经投票',
							'jifen' => '',]);
						return dr_return_data(1, $msg, $c);
							
					}
					if ($this->index['toupiaojl'] == '2') {
						//减去积分奖励
						if($toupiao['jiangli'] > 0) {
							$msg = dr_string2array(['status' => 1,
								'value' => '取消投票',
								'jifen' => $jianqujiangli,]);
							//加上发布投票者的积分
							\Phpcmf\Service::M('member')->add_score($this->index['uid'], $this->index['tpjianglijifen'], $note = '', $url = '', $mark = '', $count = 1);
							
							//减去提交投票者增加积分
							\Phpcmf\Service::M('member')->add_score($this->uid, -$this->index['tpjianglijifen'], $note = '', $url = '', $mark = '', $count = 1);
						}
					} elseif ($this->index['toupiaojl'] == '3'){
						$jianqujiangli = '减去奖励的'.$this->index['tpjlrmb'].'人民币';
						
						//增加人民币奖励
						if($toupiao['rmb'] > 0) {
							$msg = dr_string2array(['status' => 1,
								'value' => '取消投票',
								'jifen' => $jianqujiangli,]);
							//加上发布投票者的人民币
							\Phpcmf\Service::M('member')->add_money($this->index['uid'], $rmb);
							\Phpcmf\Service::M('Pay')->add_paylog([
								'uid' => $this->index['uid'],
								'username' => "",
								'touid' => "",
								'tousername' => '',
								'mid' => 'system', // 特征字符串，system表示系统
								'title' => $datatitle,
								'value' => $rmb, // 交易金额，正数表示增加金额，负数表示消费金额
								'type' => 'finecms', // 支付方式，alipy，weixin，finecms表示余额
								'status' => 1, // 1表示交易成功,0表示未成功
								'result' => $id."取消投票退回奖励的人民币",
								'paytime' => SYS_TIME, // 付款时间，默认当前时间
								'inputtime' => SYS_TIME, // 流水参生时间，默认当前时间
							]);
							
							//减去提交投票者增加积分
							\Phpcmf\Service::M('member')->add_money($this->uid, -$rmb);
							\Phpcmf\Service::M('Pay')->add_paylog([
								'uid' => $this->uid,
								'username' => "",
								'touid' => "",
								'tousername' => '',
								'mid' => 'system', // 特征字符串，system表示系统
								'title' => $datatitle,
								'value' => -$rmb, // 交易金额，正数表示增加金额，负数表示消费金额
								'type' => 'finecms', // 支付方式，alipy，weixin，finecms表示余额
								'status' => 1, // 1表示交易成功,0表示未成功
								'result' => $id."取消投票减去人民币",
								'paytime' => SYS_TIME, // 付款时间，默认当前时间
								'inputtime' => SYS_TIME, // 流水参生时间，默认当前时间
							]);
						}
					} else {
						$msg = dr_string2array(['status' => 1,
							'value' => '取消投票',
							'jifen' => $jianqujiangli,]);
					}
					
					$this->db->table($table)->where('cid', $id)->where('leixing', 1)->where('toupiaoid', $value)->where('uid', $this->uid)->delete();
				}
			} else {
				//投票
				//添加
				if ($this->index['toupiaojl'] == '2') {
					$rmb = 0;
					//减去发布投票者的积分
					\Phpcmf\Service::M('member')->add_score($this->index['uid'], -$this->index['tpjianglijifen'], $note = '', $url = '', $mark = '', $count = 1);
					
					//加上提交投票者增加积分
					\Phpcmf\Service::M('member')->add_score($this->uid, $this->index['tpjianglijifen'], $note = '', $url = '', $mark = '', $count = 1);
					
				} elseif ($this->index['toupiaojl'] == '3') {
					$rmb = $this->index['tpjlrmb']; //人民币
					//减去发布投票者的人民币
					\Phpcmf\Service::M('member')->add_money($this->index['uid'], -$this->index['tpjlrmb']);
					\Phpcmf\Service::M('Pay')->add_paylog([
						'uid' => $this->index['uid'],
						'username' => "",
						'touid' => "",
						'tousername' => '',
						'mid' => 'system', // 特征字符串，system表示系统
						'title' => $datatitle,
						'value' => -$rmb, // 交易金额，正数表示增加金额，负数表示消费金额
						'type' => 'finecms', // 支付方式，alipy，weixin，finecms表示余额
						'status' => 1, // 1表示交易成功,0表示未成功
						'result' => $id."减去投票奖励的人民币",
						'paytime' => SYS_TIME, // 付款时间，默认当前时间
						'inputtime' => SYS_TIME, // 流水参生时间，默认当前时间
					]);
					
					//奖励提交投票者增加积分
					\Phpcmf\Service::M('member')->add_money($this->uid, $this->index['tpjlrmb']);
					\Phpcmf\Service::M('Pay')->add_paylog([
						'uid' => $this->uid,
						'username' => "",
						'touid' => "",
						'tousername' => '',
						'mid' => 'system', // 特征字符串，system表示系统
						'title' => $datatitle,
						'value' => $rmb, // 交易金额，正数表示增加金额，负数表示消费金额
						'type' => 'finecms', // 支付方式，alipy，weixin，finecms表示余额
						'status' => 1, // 1表示交易成功,0表示未成功
						'result' => $id."投票奖励的人民币",
						'paytime' => SYS_TIME, // 付款时间，默认当前时间
						'inputtime' => SYS_TIME, // 流水参生时间，默认当前时间
					]);
				}
				
				$msg = dr_string2array(['status' => 1,
					'value' => '投票成功',
					'jifen' => $jianqujiangli,]);
				$this->db->table($table)->insert(array(
					'cid' => $id,
					'uid' => $this->uid,
					'toupiaoid' => $value,
					'jiangli' => $jianglijifen,
					'rmb' => $rmb,
					'leixing' => 1,
					'inputtime' => SYS_TIME
				));
			}
		} else {
			//多选模式
			$toupiao = $this->db->table($table)->where('cid', $id)->where('leixing', 1)->where('uid', $this->uid)->where('toupiaoid', $value)->get()->getRowArray();
			if ($toupiao) {
				// 取消投票,我们就删除它
				if ($this->index['qxtps']==2){
					$msg = dr_string2array(['status' => 0,
						'value' => '您已经投票',
						'jifen' => '',]);
				} else {
					if ($this->index['toupiaojl'] == '2') {
						//减去积分奖励
						if($toupiao['jiangli'] > 0) {
							$msg = dr_string2array(['status' => 1,
								'value' => '取消投票',
								'jifen' => $jianqujiangli,]);
							//加上发布投票者的积分
							\Phpcmf\Service::M('member')->add_score($this->index['uid'], $this->index['tpjianglijifen'], $note = '', $url = '', $mark = '', $count = 1);
							
							//减去提交投票者增加积分
							\Phpcmf\Service::M('member')->add_score($this->uid, -$this->index['tpjianglijifen'], $note = '', $url = '', $mark = '', $count = 1);
						}
					} elseif ($this->index['toupiaojl'] == '3'){
						//增加人民币奖励
						if($toupiao['rmb'] > 0) {
							$msg = dr_string2array(['status' => 1,
								'value' => '取消投票',
								'jifen' => $jianqujiangli,]);
							//加上发布投票者的人民币
							\Phpcmf\Service::M('member')->add_money($this->index['uid'], $rmb);
							\Phpcmf\Service::M('Pay')->add_paylog([
								'uid' => $this->index['uid'],
								'username' => "",
								'touid' => "",
								'tousername' => '',
								'mid' => 'system', // 特征字符串，system表示系统
								'title' => $datatitle.'返回奖励金'.+$rmb,
								'value' => $rmb, // 交易金额，正数表示增加金额，负数表示消费金额
								'type' => 'finecms', // 支付方式，alipy，weixin，finecms表示余额
								'status' => 1, // 1表示交易成功,0表示未成功
								'result' => $id."取消投票退回奖励的人民币",
								'paytime' => SYS_TIME, // 付款时间，默认当前时间
								'inputtime' => SYS_TIME, // 流水参生时间，默认当前时间
							]);
							
							//减去加上提交投票者增加积分
							\Phpcmf\Service::M('member')->add_money($this->uid, -$rmb);
							\Phpcmf\Service::M('Pay')->add_paylog([
								'uid' => $this->uid,
								'username' => "",
								'touid' => "",
								'tousername' => '',
								'mid' => 'system', // 特征字符串，system表示系统
								'title' => $datatitle.'扣取奖励金'.-$rmb,
								'value' => -$rmb, // 交易金额，正数表示增加金额，负数表示消费金额
								'type' => 'finecms', // 支付方式，alipy，weixin，finecms表示余额
								'status' => 1, // 1表示交易成功,0表示未成功
								'result' => $id."取消投票减去奖励的人民币",
								'paytime' => SYS_TIME, // 付款时间，默认当前时间
								'inputtime' => SYS_TIME, // 流水参生时间，默认当前时间
							]);
						}
					} else {
						$msg = dr_string2array(['status' => 1,
							'value' => '取消投票',
							'jifen' => $jianqujiangli,]);
					}
					$this->db->table($table)->where('cid', $id)->where('leixing', 1)->where('toupiaoid', $value)->where('uid', $this->uid)->delete();
				}
			} else {
				//添加
				if ($this->index['toupiaojl'] == '2') {
					//减去发布投票者的积分
					\Phpcmf\Service::M('member')->add_score($this->index['uid'], -$this->index['tpjianglijifen'], $note = '', $url = '', $mark = '', $count = 1);
					
					//加上提交投票者增加积分
					\Phpcmf\Service::M('member')->add_score($this->uid, $this->index['tpjianglijifen'], $note = '', $url = '', $mark = '', $count = 1);
					$rmb=0;
				} elseif ($this->index['toupiaojl'] == '3') {
					$rmb = $this->index['tpjlrmb']; //人民币
					//减去发布投票者的人民币
					\Phpcmf\Service::M('member')->add_money($this->index['uid'], -$this->index['tpjlrmb']);
					\Phpcmf\Service::M('Pay')->add_paylog([
						'uid' => $this->index['uid'],
						'username' => "",
						'touid' => "",
						'tousername' => '',
						'mid' => 'system', // 特征字符串，system表示系统
						'title' => $datatitle,
						'value' => -$rmb, // 交易金额，正数表示增加金额，负数表示消费金额
						'type' => 'finecms', // 支付方式，alipy，weixin，finecms表示余额
						'status' => 1, // 1表示交易成功,0表示未成功
						'result' => $id."减去投票奖励的人民币",
						'paytime' => SYS_TIME, // 付款时间，默认当前时间
						'inputtime' => SYS_TIME, // 流水参生时间，默认当前时间
					]);
					
					//奖励提交投票者增加积分
					\Phpcmf\Service::M('member')->add_money($this->uid, $this->index['tpjlrmb']);
					\Phpcmf\Service::M('Pay')->add_paylog([
						'uid' => $this->uid,
						'username' => "",
						'touid' => "",
						'tousername' => '',
						'mid' => 'system', // 特征字符串，system表示系统
						'title' => $datatitle,
						'value' => $rmb, // 交易金额，正数表示增加金额，负数表示消费金额
						'type' => 'finecms', // 支付方式，alipy，weixin，finecms表示余额
						'status' => 1, // 1表示交易成功,0表示未成功
						'result' => $id."投票奖励的人民币",
						'paytime' => SYS_TIME, // 付款时间，默认当前时间
						'inputtime' => SYS_TIME, // 流水参生时间，默认当前时间
					]);
				}
				$msg = dr_string2array(['status' => 1,
					'value' => '投票成功',
					'jifen' => $jianqujiangli,]);
				$this->db->table($table)->insert(array(
					'cid' => $id,
					'uid' => $this->uid,
					'toupiaoid' => $value,
					'jiangli' => $jianglijifen,
					'rmb' => $rmb,
					'leixing' => 1,
					'inputtime' => SYS_TIME
				));
			}
		}
		
	
		// 更新缓存
		//$c = $this->db->table($tablename.'_form_son_zan')->where('cid', $id)->countAllResults();
		//$this->db->table($tablename.'_form_son')->where('id', $id)->set('zan', $c)->update();
		\Phpcmf\Service::M('cache')->update_data_cache();
	
		// 返回结果
		return dr_return_data(1, $msg, $c);
	
	}
	/*下载次数计算*/
	public function xiazaicishu($tablename, $mid) {
		$id = (int)\Phpcmf\Service::L('input')->get('id');
		$uid = (int)\Phpcmf\Service::L('input')->get('uid');
		$file = (int)\Phpcmf\Service::L('input')->get('file');
		if (!$this->uid) {
			$msg = dr_string2array(['status' => 1,
			    'value' => '您好,还没有登录',
				'jifen' => '',]);
				
		    return dr_return_data(0, $msg, $c);
		} elseif (!$id) {
			$msg = dr_string2array(['status' => 0,
			    'value' => 'id参数不完整',
				'jifen' => '',]);
		    return dr_return_data(0, $msg, $c);
		}
		//$quanid = (int)\Phpcmf\Service::L('input')->get('quanid');
		$table = '1_quan_xiazai';
		
		$xiazais = \Phpcmf\Service::M()->db->table('1_quan_shezhi')->where('dirname', 'tiezi')->get()->getRowArray();
		$xiazaixianzhi = dr_string2array($xiazais['setting']);
		$xiazaishu = $xiazaixianzhi['pages']['setting']['xiazaixianzhi'];
		//下载总数
		$xiazaitongji = $this->db->table($table)->where('uid', $this->uid)->countAllResults();
		$xiazais = $xiazaishu - $xiazaitongji;
		//dr_debug('xiazaitongji', $xiazaishu.'/'.$xiazaitongji);
		if ($xiazaitongji < $xiazaishu){
			$unxiazai = $this->db->table($table)->where('cid', $id)->where('uid', $this->uid)->get()->getRowArray();
			if($unxiazai) {
				//二次开发
			} else {
				$this->db->table($table)->insert(array(
				    'cid' => $id,
				    'uid' => $this->uid,
					'inputtime' => SYS_TIME,
				    'inputtime' => SYS_TIME
				));
			}
			$msg = dr_string2array(['status' => 1,
			    'value' => '您好,下载成功。今天还有'.$xiazais.'次下载',
				'jifen' => dr_url_rel(dr_down_file($file)),]);
			//更新
		} else {
			$msg = dr_string2array(['status' => 1,
			    'value' => '您好,一天只限制'.$xiazaishu.'次下载',
				'jifen' => '',]);
		}
		return dr_return_data(1, $msg, $c);
	}
	// 副圈主申请
	public function fuquanzhu($tablename, $dirname) {
	
	
	    $quanid = (int)\Phpcmf\Service::L('input')->get('quanid');
	    if (!$this->uid) {
	        return dr_return_data(0, dr_lang('还没有登录'));
	    } elseif (!$quanid) {
	        return dr_return_data(0, dr_lang('id参数不完整'));
	    }
	    
	    $table = $tablename.'_form_son';
		$tableguanli = $tablename.'_guanli';
	    /*if (!$this->db->tableExists($table) ) {
	        return dr_return_data(0, dr_lang('应用[模块内容收藏]未安装到本模块[%s]', $dirname));
	    }*/
		
		$tabledata = $this->db->table($tablename)->where('id', $quanid)->get()->getRowArray();
		$tableguanlidata = $this->db->table($tableguanli)->where('quanid', $quanid)->where('uid',  $this->uid)->get()->getRowArray();
		if($tableguanlidata){
			if($tableguanlidata['zhuangtai']==0){
				$msg = dr_string2array(['status' => 0,
				    'value' => '等待核对中',
					'jifen' => '',]);
			} elseif ($tableguanlidata['zhuangtai']==1){
				$msg = dr_string2array(['status' => 1,
				    'value' => '您已经是圈主',
					'jifen' => '',]);
			} elseif ($tableguanlidata['zhuangtai']==2){
				$msg = dr_string2array(['status' => 0,
				    'value' => '没有通过，请联系圈主',
					'jifen' => '',]);
			}
		} else {
			if($tabledata){
				if($tabledata['kqsq']==1){
					//统计个人帖子数量
					$tiezitongji = $this->db->table($table)->where('uid', $this->uid)->countAllResults();
					
					// 判断发布帖子数量
					if($tabledata['fatieyaoqiu'] > 0){
						if($tiezitongji > $tabledata['fatieyaoqiu']){
							//实名认证
							if($tabledata['smyq'] == 1){
								if(dr_is_app('certify')){
									$arr=\Phpcmf\Service::C()->get_cache("app-certify");
									$rzs = [];
									foreach ($arr as $a) {  
										$rz = \Phpcmf\Service::M('data', 'certify')->info($a.code, $this->uid);
										if ($a['value']['xianshi'] ==1){
											if($rz){
												if($rz['status'] ==1){
													$rzs[] = 1;
												}
											}
										}
										if($rzs) {
											// 执行添加
											$this->db->table($tableguanli)->insert(array(
											    'quanid' => $quanid,
											    'uid' => $this->uid,
												'guanlizu' => '0',
												'zhuangtai' => '10',
												'inputtime' => SYS_TIME,
											    'endtime' => 0
											));
											$msg = dr_string2array(['status' => 1,
											    'value' => '提交成功，等待核对',
												'jifen' => '',]);
											//通知
											$data = [
												'catid'=> 15, //类型
												'title' => '申请圈子管理员', //标题
												'zhiding' => '', //置顶
												'content'=> '申请圈子管理员', //通知内容
												'uid'=> $this->uid, //发布人的uid
												'faxinren'=> $this->uid, //发布人的uid
												'shouxinren'=> (int)$tabledata['uid'],//收信人
												'tupian'=> '', //图片
												'shipin'=> '', //视频
												'yuyin'=> '', //语音
												'fujian'=> '', //附件
												'yidu'=> 0, //已读
												'quanziid'=> $tabledata['id'], //圈子ID
												'quantieid'=> 0, //圈帖ID
												'url' => '',
											];
											\Phpcmf\Service::M('auth')->addtongzhi($data);
										} else {
											$msg = dr_string2array(['status' => 0,
											    'value' => '您还没有实名认证',
												'jifen' => '',]);
										}
									    //echo $fruit . "<br>";  
									}
								} else {
									$msg = dr_string2array(['status' => 0,
									    'value' => '没有安装实名插件',
										'jifen' => '',]);
								}
							} else {
								// 执行添加
								$this->db->table($tableguanli)->insert(array(
								    'quanid' => $quanid,
								    'uid' => $this->uid,
									'guanlizu' => '0',
									'zhuangtai' => '10',
									'inputtime' => SYS_TIME,
								    'endtime' => 0
								));
								$msg = dr_string2array(['status' => 1,
								    'value' => '提交成功，等待核对',
									'jifen' => '',]);
								//通知
								$data = [
									'catid'=> 15, //类型
									'title' => '申请圈子管理员', //标题
									'zhiding' => '', //置顶
									'content'=> '申请圈子管理员', //通知内容
									'uid'=> $this->uid, //发布人的uid
									'faxinren'=> $this->uid, //发布人的uid
									'shouxinren'=> (int)$tabledata['uid'],//收信人
									'tupian'=> '', //图片
									'shipin'=> '', //视频
									'yuyin'=> '', //语音
									'fujian'=> '', //附件
									'yidu'=> 0, //已读
									'quanziid'=> $tabledata['id'], //圈子ID
									'quantieid'=> 0, //圈帖ID
									'url' => '',
								];
								\Phpcmf\Service::M('auth')->addtongzhi($data);
							}
						} else {
							$msg = dr_string2array(['status' => 0,
							    'value' => '您发布帖子没有达到'.$tabledata['fatieyaoqiu'].'条',
								'jifen' => '',]);
						}
						
							
					} else {
						// 执行添加
						//实名认证
						if($tabledata['smyq'] == 1){
							if(dr_is_app('certify')){
								$arr=\Phpcmf\Service::C()->get_cache("app-certify");
								$rzs = [];
								foreach ($arr as $a) {  
									$rz = \Phpcmf\Service::M('data', 'certify')->info($a.code, $this->uid);
									if ($a['value']['xianshi'] ==1){
										if($rz){
											if($rz['status'] ==1){
												$rzs[] = 1;
											}
										}
									}
									if($rzs) {
										// 执行添加
										$this->db->table($tableguanli)->insert(array(
										    'quanid' => $quanid,
										    'uid' => $this->uid,
											'guanlizu' => '0',
											'zhuangtai' => '10',
											'inputtime' => SYS_TIME,
										    'endtime' => 0
										));
										$msg = dr_string2array(['status' => 1,
										    'value' => '提交成功，等待核对',
											'jifen' => '',]);
										//通知
										$data = [
											'catid'=> 15, //类型
											'title' => '申请圈子管理员', //标题
											'zhiding' => '', //置顶
											'content'=> '申请圈子管理员', //通知内容
											'uid'=> $this->uid, //发布人的uid
											'faxinren'=> $this->uid, //发布人的uid
											'shouxinren'=> (int)$tabledata['uid'],//收信人
											'tupian'=> '', //图片
											'shipin'=> '', //视频
											'yuyin'=> '', //语音
											'fujian'=> '', //附件
											'yidu'=> 0, //已读
											'quanziid'=> $tabledata['id'], //圈子ID
											'quantieid'=> 0, //圈帖ID
											'url' => '',
										];
										\Phpcmf\Service::M('auth')->addtongzhi($data);
									} else {
										$msg = dr_string2array(['status' => 0,
										    'value' => '您还没有实名认证',
											'jifen' => '',]);
									}
								    //echo $fruit . "<br>";  
								}
							} else {
								$msg = dr_string2array(['status' => 0,
								    'value' => '没有安装实名插件',
									'jifen' => '',]);
							}
							
						} else {
							// 执行添加
							$this->db->table($tableguanli)->insert(array(
							    'quanid' => $quanid,
							    'uid' => $this->uid,
								'guanlizu' => '0',
								'zhuangtai' => '10',
								'inputtime' => SYS_TIME,
							    'endtime' => 0
							));
							$msg = dr_string2array(['status' => 1,
							    'value' => '提交成功，等待核对',
								'jifen' => '',]);
							//通知
							$data = [
								'catid'=> 15, //类型
								'title' => '申请圈子管理员', //标题
								'zhiding' => '', //置顶
								'content'=> '申请圈子管理员', //通知内容
								'uid'=> $this->uid, //发布人的uid
								'faxinren'=> $this->uid, //发布人的uid
								'shouxinren'=> (int)$tabledata['uid'],//收信人
								'tupian'=> '', //图片
								'shipin'=> '', //视频
								'yuyin'=> '', //语音
								'fujian'=> '', //附件
								'yidu'=> 0, //已读
								'quanziid'=> $tabledata['id'], //圈子ID
								'quantieid'=> 0, //圈帖ID
								'url' => '',
							];
							\Phpcmf\Service::M('auth')->addtongzhi($data);
						}
					}
				} else {
					$msg = dr_string2array(['status' => 0,
					    'value' => '没有开通申请',
						'jifen' => '',]);
				}
			} else {
				$msg = dr_string2array(['status' => 0,
				    'value' => '没有这个圈子',
					'jifen' => '',]);
			}
		}
	    // 返回结果
	    return dr_return_data(1, $msg, $c);
	
	}
	// 副圈主申请
	public function guanlizu($tablename, $dirname) {
	
	    $guanlizuid = (int)\Phpcmf\Service::L('input')->get('guanlizuid');
	    $quanid = (int)\Phpcmf\Service::L('input')->get('quanid');
		$uid = (int)\Phpcmf\Service::L('input')->get('uid');
	    if (!$this->uid) {
	        return dr_return_data(0, dr_lang('还没有登录'));
	    } elseif (!$uid) {
	        return dr_return_data(0, dr_lang('用户的id为空'));
	    } elseif (!$quanid) {
	        return dr_return_data(0, dr_lang('圈子的id为空'));
	    } elseif (!$guanlizuid) {
	        return dr_return_data(0, dr_lang('管理员ID为空。请添加管理组'));
	    }
	    
	    $table = $tablename.'_form_son';
		$tableguanli = $tablename.'_guanli';
	    /*if (!$this->db->tableExists($table) ) {
	        return dr_return_data(0, dr_lang('应用[模块内容收藏]未安装到本模块[%s]', $dirname));
	    }*/
		
		$tabledata = $this->db->table($tablename)->where('id', $quanid)->where('uid', $this->uid)->get()->getRowArray();
		if (!$tabledata) {
		    return dr_return_data(0, dr_lang('没有权限操作'));
		} else {
			$this->db->table($tableguanli)->where('quanid', $quanid)->where('uid', $uid)->set('guanlizu', $guanlizuid)->update();
			$msg = dr_string2array(['status' => 0,
			    'value' => '选择成功',
				'jifen' => '',]);
		}
		
		
		
		
		// 返回结果
		return dr_return_data(1, $msg, $c);
	}
	
	// 副圈主申请状态
	public function guanlizuzhuangtai($tablename, $dirname) {
	
	    $guanlizuid = (int)\Phpcmf\Service::L('input')->get('guanlizuid');
	    $quanid = (int)\Phpcmf\Service::L('input')->get('quanid');
		$uid = (int)\Phpcmf\Service::L('input')->get('uid');
		$ztid = (int)\Phpcmf\Service::L('input')->get('ztid');
	    if (!$this->uid) {
	        return dr_return_data(0, dr_lang('还没有登录'));
	    } elseif (!$uid) {
	        return dr_return_data(0, dr_lang('用户的id不能为空'));
	    } elseif (!$quanid) {
	        return dr_return_data(0, dr_lang('圈子的id不能为空'));
	    } elseif (!$guanlizuid) {
	        return dr_return_data(0, dr_lang('管理员ID为空。请添加管理组'));
	    } elseif (!$ztid) {
	        return dr_return_data(0, dr_lang('id不能为空'));
	    }
	    $table = $tablename.'_form_son';
		$tableguanli = $tablename.'_guanli';
	    /*if (!$this->db->tableExists($table) ) {
	        return dr_return_data(0, dr_lang('应用[模块内容收藏]未安装到本模块[%s]', $dirname));
	    }*/
		
		$tabledata = $this->db->table($tablename)->where('id', $quanid)->where('uid', $this->uid)->get()->getRowArray();
		$guanlidata = $this->db->table($tableguanli)->where('quanid', $quanid)->where('uid', $uid)->get()->getRowArray();
		if (!$tabledata) {
		    return dr_return_data(0, dr_lang('没有权限操作'));
		} else {
			//
			if($ztid == 1){
				if($guanlidata['guanlizu'] == 0){
					$msg = dr_string2array(['status' => 0,
					    'value' => '请选择用户组',
						'jifen' => '',]);
				} else {
					$this->db->table($tableguanli)->where('quanid', $quanid)->where('uid', $uid)->set('zhuangtai', $ztid)->update();
					$msg = dr_string2array(['status' => 1,
					    'value' => '操作成功',
						'jifen' => '',]);
				}
				
			} elseif ($ztid == 2) {
				$this->db->table($tableguanli)->where('quanid', $quanid)->where('uid', $uid)->set('zhuangtai', $ztid)->update();
				$msg = dr_string2array(['status' => 2,
				    'value' => '操作成功',
					'jifen' => '',]);
			} elseif ($ztid == 4) {
				$this->db->table($tableguanli)->where('quanid', $quanid)->where('uid', $uid)->delete();
				$msg = dr_string2array(['status' => 4,
				    'value' => '操作成功',
					'jifen' => '',]);
			}
		}
		// 返回结果
		return dr_return_data(1, $msg, $c);
	}

}